Skip to content

Commit 6846707

Browse files
Add create_app to previne circular import
1 parent bd0c5c6 commit 6846707

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

manage.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from flask_script import Manager
2-
from tvseries import app
2+
from tvseries import create_app
3+
from tvseries.config import DevelopmentConfig
34

5+
app = create_app(config=DevelopmentConfig)
46
manager = Manager(app)
57

68
if __name__ == "__main__":

tvseries/__init__.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
from tvseries.ext import db
55
from tvseries.core import core_blueprint
66

7-
print("Problem: Hen and egg (python circular imports)")
8-
app = Flask(__name__)
9-
app.config.from_object(config.DevelopmentConfig)
10-
app.register_blueprint(core_blueprint, url_prefix='/')
11-
db.init_app(app)
7+
8+
def create_app(config=config.ProductionConfig):
9+
app = Flask(__name__)
10+
app.config.from_object(config)
11+
app.register_blueprint(core_blueprint, url_prefix='/')
12+
db.init_app(app)
13+
return app

tvseries/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class BaseConfig(object):
66
SECRET_KEY = config('SECRET_KEY')
77
SERVER_NAME = config('SERVER_NAME')
88
SQLALCHEMY_DATABASE_URI = config('DATABASE_URI')
9+
SQLALCHEMY_TRACK_MODIFICATIONS = True
910
DEBUG = False
1011
TESTING = False
1112

tvseries/tests/test_core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class TestCore:
99

1010
@pytest.fixture
1111
def app(self):
12-
from tvseries import app
13-
app.config.from_object(TestConfig)
12+
from tvseries import create_app
13+
app = create_app(TestConfig)
1414
return app
1515

1616
def test_get_home(self, db):

0 commit comments

Comments
 (0)