35 lines
745 B
Python
35 lines
745 B
Python
import os
|
|
|
|
from flask import Flask
|
|
from flask_migrate import Migrate
|
|
|
|
from .config import config
|
|
from .dependencies import db, ma
|
|
from .commands.startapp import startapp
|
|
from .utils import import_models
|
|
|
|
|
|
def create_app(config_name: str = None) -> Flask:
|
|
if config_name is None:
|
|
config_name = os.environ.get("FLASK_ENV")
|
|
|
|
app = Flask(__name__)
|
|
app.config.from_object(config.get(config_name) or config.get("development"))
|
|
|
|
db.init_app(app)
|
|
ma.init_app(app)
|
|
|
|
if config_name != "production":
|
|
with app.app_context():
|
|
import_models()
|
|
|
|
Migrate(app, db)
|
|
|
|
# register blueprints
|
|
# app.register_blueprint(blueprint)
|
|
|
|
# register commands
|
|
app.cli.add_command(startapp)
|
|
|
|
return app
|