You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1KB

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