38 lines
986 B
Python
38 lines
986 B
Python
import os
|
|
from dotenv import load_dotenv
|
|
from flask import Flask
|
|
from the_works.database import init_db
|
|
from flask_debugtoolbar import DebugToolbarExtension
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
|
|
# read config values
|
|
load_dotenv()
|
|
app.config.from_prefixed_env()
|
|
if os.getenv("SQLALCHEMY_DATABASE_DIALECT") == "sqlite":
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///" + os.path.abspath(app.root_path + "/..") + "/" + os.getenv("SQLALCHEMY_DATABASE_SQLITE_FILENAME")
|
|
else:
|
|
pass
|
|
|
|
# DEBUG
|
|
app.config["SQLALCHEMY_ECHO"] = True
|
|
|
|
print(f"Current Environment: " + app.config['ENVIRONMENT'])
|
|
print(f"SQLAlchemy DB URI: " + app.config['SQLALCHEMY_DATABASE_URI'])
|
|
|
|
# initialize database
|
|
init_db(app)
|
|
|
|
# register blueprints
|
|
from the_works.views import home, text, werk
|
|
app.register_blueprint(text.bp)
|
|
app.register_blueprint(home.bp)
|
|
app.register_blueprint(werk.bp)
|
|
|
|
# load debug toolbar
|
|
toolbar = DebugToolbarExtension(app)
|
|
|
|
return app
|