mirror of
https://github.com/Xevion/runnerspace.git
synced 2025-12-05 23:16:12 -06:00
Fix circular imports issue by separating SQLAlchemy db instance into database.py
This commit is contained in:
5
app.py
5
app.py
@@ -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)
|
||||
|
||||
|
||||
2
auth.py
2
auth.py
@@ -3,7 +3,7 @@ from flask_login import login_required, login_user, logout_user, current_user
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
from models import User
|
||||
from app import db
|
||||
from database import db
|
||||
|
||||
blueprint = Blueprint('auth', __name__)
|
||||
|
||||
|
||||
3
database.py
Normal file
3
database.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
db = SQLAlchemy()
|
||||
2
forms.py
2
forms.py
@@ -1,7 +1,7 @@
|
||||
from flask import Blueprint, flash, redirect, request, url_for
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
from app import db
|
||||
from database import db
|
||||
from models import User, Post, Comment
|
||||
|
||||
blueprint = Blueprint('forms', __name__)
|
||||
|
||||
Reference in New Issue
Block a user