Created
December 3, 2023 17:49
-
-
Save rnelsonchem/5c0a86c8fc2764b5889e4a81a16ad2c3 to your computer and use it in GitHub Desktop.
My test Flask app main file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import click | |
from flask import Flask | |
from flask.cli import with_appcontext | |
from flask_sqlalchemy import SQLAlchemy | |
from sqlalchemy.orm import DeclarativeBase | |
class Base(DeclarativeBase): | |
pass | |
db = SQLAlchemy(model_class=Base) | |
@click.command("init-db") | |
@with_appcontext | |
def init_db_command(): | |
print("Initializing the database.") | |
db.drop_all() | |
db.create_all() | |
def create_app(test_config=None): | |
app = Flask(__name__, instance_relative_config=True) | |
app.config.from_mapping( | |
SECRET_KEY="dev", | |
SQLALCHEMY_DATABASE_URI="sqlite:///rmapp.sqlite" | |
) | |
db.init_app(app) | |
app.cli.add_command(init_db_command) | |
from . import page | |
app.register_blueprint(page.bp) | |
return app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment