问题描述
我的问题类似于,但我似乎无法解决它使用他们解决方案。
My Flask应用程序具有以下结构:
appname /
run.py
Procfile
venv /
...
appname /
app.py
views.py
run.py:
from appname import app
app.run(debug = True)
app。 py:
from flask import Flask
app = Flask(__ name__)
@app .route('/')
def home():
返回here
Procfile:
web:gunicorn --pythonpath appname app:app
views.py:
from appname import app $ b $ from flask import render_template
@ app.route('/ there')
def there():
return在那里
以前,我在运行 foreman start时遇到了erorrs
,但是一旦我从 app.py
中删除 import appname.views
,这些就会消失。
现在, foreman start
运行应用程序并路由 /
是可访问的,但 / there
不是。怎么样?
应用程序结构(不变):
appname /
run.py
Procfile
venv /
...
appname /
app。 py
views.py
run.py(不变):
from appname import app
app.run(debug = True)
app.py:
import Flask
app = Flask(__ name__)
import appname.views
import appname.anothermodule
$ b Procfile:
web:gunicorn appname:app
views.py(不变):
<$ ($)
def home():
returnHello,awesomeness!pre $ from appname import app
@ app.route('/')
def home
My problem is similar to Flask and Gunicorn on Heroku import error and Procfile gunicorn custom module name but I can't seem to fix it using their solutions.
My Flask app has the following structure:
appname/
run.py
Procfile
venv/
...
appname/
app.py
views.py
run.py:
from appname import app
app.run(debug=True)
app.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "here"
Procfile:
web: gunicorn --pythonpath appname app:app
views.py:
from appname import app
from flask import render_template
@app.route('/there')
def there():
return "there"
Previously, I was experiencing erorrs when running foreman start
, but those went away once I removed import appname.views
from app.py
.
Now, foreman start
runs the app and route /
is accessible but /there
is not. How come?
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!"
这篇关于烧瓶和gunicorn,多个模块:循环进口 - 并非所有的路线可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!