Flask and gunicorn, multiple modules: circular imports - not all routes accessible

元气小坏坏 提交于 2019-12-05 21:44:31

Hooray! I've been able to have it work with the code I really wanted.

app structure (unchanged):

appname/
   run.py
   Procfile
   venv/
       ...
   appname/
       app.py
       views.py

run.py (unchanged):

from appname import app
app.run(debug=True)

app.py:

from flask import Flask
app = Flask(__name__)

import appname.views
import appname.anothermodule

Procfile:

web: gunicorn appname:app

views.py (unchanged):

from appname import app

@app.route('/')
def home():
    return "Hello, awesomeness!"

I've been able to move "around" this issue, by:

  1. Not having from appname import app anywhere else other than in run.py
  2. Consequently, only defining routes in app.py

I would have preferred to keep my routes with my modules, although I am unsure which is the better Python style.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!