Skip to content
Snippets Groups Projects
app.py 1.41 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alex's avatar
    Alex committed
    from flask import Flask, send_from_directory
    
    Alex's avatar
    Alex committed
    
    
    from database.db import db
    from config.config import APP_NAME, ENV, get_app_config, get_static_url
    
    Alex's avatar
    Alex committed
    
    
    # Create and configure our Flask app
    app = Flask(__name__, static_url_path=get_static_url())
    app.url_map.strict_slashes = False
    app.config.from_object(get_app_config())
    
    Alex's avatar
    Alex committed
    
    
    db.init_app(app)
    
    Alex's avatar
    Alex committed
    
    
    Alex's avatar
    Alex committed
    # TODO Find a workaround for migrations/db.create_all()
    with app.app_context():
        from models.entity import Entity
    
    Alex's avatar
    Alex committed
        if app.config["SQLALCHEMY_DATABASE_URI"]:
            db.create_all()
    
    
    
    # Serve all static assets for the frontend
    @app.route('/static/<path:path>')
    def serve_static_files(path):
        return send_from_directory('static', path)
    
    
    # Register all routes from the blueprints module
    from blueprints.home import home_blueprint
    from blueprints.auth import auth_blueprint
    app.register_blueprint(home_blueprint)
    app.register_blueprint(auth_blueprint)
    
    # @app.route('/test-db')
    # def test_db():
    #     try:
    #         rows = ""
    
    #         for user in db.session.query(User).all():
    #             rows += str(user) + " "
    
    #         for e in db.session.query(Entity).all():
    #             rows += str(e) + " "
    
    #         print("All rows:", rows)
    #         return rows
    #     except:
    #         return "App database error"
    
    # Hook any custom Jinja templating functions
    from config import CUSTOM_TEMPLATE_FUNCTIONS
    app.jinja_env.globals.update(CUSTOM_TEMPLATE_FUNCTIONS)
    
    if __name__ == '__main__':
        app.run()