Newer
Older
from flask import Flask, send_from_directory, url_for
from database.db import db
from config.config import APP_NAME, ENV, get_app_config, get_static_url
# 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())
# uri = os.getenv("DATABASE_URL") # or other relevant config var
# print(uri)
# # if uri and uri.startswith("postgres://"):
# # uri = uri.replace("postgres://", "postgresql://", 1)
# # app.config["SQLALCHEMY_DATABASE_URI"] = uri
# # db = SQLAlchemy(app)
# # if db.session.query(User).filter_by(username="testuser").first() is not None:
# # db.session.add(User(username='testuser', email='admin@example.com'))
# # db.session.commit()
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# # if db.session.query(Entity).filter_by(username="my entity").first() is not None:
# # db.session.add(Entity(username='my entity', email='entity@example.com'))
# # db.session.commit()
# # else:
# # print("No database created/linked with this application")
# 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()