Fix circular imports issue by separating SQLAlchemy db instance into database.py

This commit is contained in:
Xevion
2022-03-28 17:57:52 -05:00
parent 3ea945b99f
commit 2d014628e4
7 changed files with 9 additions and 6 deletions

5
app.py
View File

@@ -9,8 +9,7 @@ from flask import Flask, render_template, request
from flask_login import LoginManager, current_user
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash
db = SQLAlchemy()
from database import db
def create_app():
@@ -25,7 +24,7 @@ def create_app():
# Heroku deployment
if app.config['ENV'] == 'production':
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL').replace('postgres://', 'postgresql://', 1)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', '').replace('postgres://', 'postgresql://', 1)
db.init_app(app)