From 82f3477d1da673ce4f19be8522561f15716dacd9 Mon Sep 17 00:00:00 2001 From: Gabriel De Los Rios Date: Sun, 29 Sep 2024 17:36:30 -0300 Subject: [PATCH] refactor: adds new entry point and ORM --- app.py | 11 ----------- app/__init__.py | 16 ++++++++++++++++ app/extensions.py | 2 ++ config.py | 10 ++++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) delete mode 100644 app.py create mode 100644 app/__init__.py create mode 100644 app/extensions.py create mode 100644 config.py diff --git a/app.py b/app.py deleted file mode 100644 index 0ea086b..0000000 --- a/app.py +++ /dev/null @@ -1,11 +0,0 @@ -from flask_sqlalchemy import SQLAlchemy -from flask import Flask, render_template - -db = SQLAlchemy() -app = Flask(__name__) -app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///adogapet.db" -db.init_app(app) - -@app.route("/") -def hello_world(): - return render_template("index.html") diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..d169868 --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,16 @@ +from flask import Flask + +from config import Config +from app.extensions import db + +def create_app(config_class=Config): + app = Flask(__name__) + app.config.from_object(config_class) + db.init_app(app) + # Initialize Flask extensions here + + # Register blueprints here + from app.main import bp as main_bp + app.register_blueprint(main_bp) + + return app \ No newline at end of file diff --git a/app/extensions.py b/app/extensions.py new file mode 100644 index 0000000..589c64f --- /dev/null +++ b/app/extensions.py @@ -0,0 +1,2 @@ +from flask_sqlalchemy import SQLAlchemy +db = SQLAlchemy() \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..a21f885 --- /dev/null +++ b/config.py @@ -0,0 +1,10 @@ +import os + +basedir = os.path.abspath(os.path.dirname(__file__)) + + +class Config: + SECRET_KEY = os.environ.get('SECRET_KEY') + SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URI')\ + or 'sqlite:///' + os.path.join(basedir, 'instance\\adogapet.db') + SQLALCHEMY_TRACK_MODIFICATIONS = False