【发布时间】:2014-06-17 12:17:43
【问题描述】:
我知道 Flask 在调试模式下会检测到对 .py 源代码文件的更改,并会在新请求进入时重新加载它们。
我过去常常在我的应用程序中看到这个。在我的views.py 文件的@app.route 装饰部分中更改一些文本,刷新后我可以在浏览器中看到更改。
但是突然之间(不记得发生了什么变化),这似乎不再起作用了。
问:我哪里出错了?
我在 OSX 10.9 系统上运行,并使用 Python 2.7 进行了 VENV 设置。我在我的项目根目录中使用foreman start 来启动它。
应用结构是这样的:
[Project Root]
+-[app]
| +-__init__.py
| +- views.py
| +- ...some other files...
+-[venv]
+- config.py
+- Procfile
+- run.py
文件如下所示:
# Procfile
web: gunicorn --log-level=DEBUG run:app
# config.py
contains some app specific configuration information.
# run.py
from app import app
if __name__ == "__main__":
app.run(debug = True, port = 5000)
# __init__.py
from flask import Flask
from flask.ext.login import LoginManager
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.mail import Mail
import os
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
#mail sending
mail = Mail(app)
lm = LoginManager()
lm.init_app(app)
lm.session_protection = "strong"
from app import views, models
# app/views.py
@app.route('/start-scep')
def start_scep():
startMessage = '''\
<html>
<header>
<style>
body { margin:40px 40px;font-family:Helvetica;}
h1 { font-size:40px; }
p { font-size:30px; }
a { text-decoration:none; }
</style>
</header>
<p>Some text</p>
</body>
</html>\
'''
response = make_response(startMessage)
response.headers['Content-Type'] = "text/html"
print response.headers
return response
【问题讨论】:
-
-
@SeanVieira 我在命令行中使用
foreman start。我应该做foreman run python run.py吗? -
是的,这就是您想要做的(很可能)——如果这不起作用,请改用
python run.py。