您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

40 行
1.1KB

  1. from flask import Flask
  2. from flask_sqlalchemy import SQLAlchemy
  3. from flask_login import LoginManager
  4. # init SQLAlchemy so we can use it later in our models
  5. db = SQLAlchemy()
  6. def create_app():
  7. app = Flask(__name__)
  8. app.config['SECRET_KEY'] = 'f9DWPyF70N'
  9. app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
  10. db.init_app(app)
  11. login_manager = LoginManager()
  12. login_manager.login_view = 'auth.login'
  13. login_manager.init_app(app)
  14. from .models import User
  15. @login_manager.user_loader
  16. def load_user(user_id):
  17. # since the user_id is just the primary key of our user table, use it in the query for the user
  18. return User.query.get(int(user_id))
  19. # blueprint for auth routes in our app
  20. from .auth import auth as auth_blueprint
  21. app.register_blueprint(auth_blueprint)
  22. # blueprint for non-auth parts of app
  23. from .main import main as main_blueprint
  24. app.register_blueprint(main_blueprint)
  25. # blueprint for tools parts of app
  26. from .tool import tool as tool_blueprint
  27. app.register_blueprint(tool_blueprint)
  28. return app