Lerndatenbank/app.py
2024-08-05 16:36:41 +02:00

30 lines
1.2 KiB
Python

from flask import Flask, render_template, request, jsonify
from flask_sqlalchemy import SQLAlchemy
# Initialize the database object
db = SQLAlchemy()
def create_app():
# Create a new Flask application instance
app = Flask(__name__)
# Configure the SQLite database URI for the application
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///mydatabase.db'
# Disable tracking modifications to SQLAlchemy objects
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Initialize the database object with the Flask application instance
db.init_app(app)
# Import and initialize models, then create tables within the app context
with app.app_context():
from models import User # Assuming there is a file named models.py containing the User model
from utils import check_and_create_tables # Assuming there is a file named utils.py containing the check_and_create_tables function
check_and_create_tables(db) # Call the function to ensure tables are created if they don't exist
return app
if __name__ == '__main__':
# Create and run the Flask application instance with debugging enabled
app = create_app()
app.run(debug=True)