当我尝试更新 Flask 中的 __init__.py 文件时,它不会显示服务器中的更改,但当我编辑 home.html
时它会起作用很好。
app/__init__.py
import os
from flask import Flask, render_template
from werkzeug.contrib.fixers import ProxyFix
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
app.wsgi_app = ProxyFix(app.wsgi_app)
app.debug = bool(os.environ.get('PRODUCTION'))
if __name__ == '__main__':
app.run()
有什么建议吗?
最佳答案
我们在评论中解决了问题,但如果其他人有类似的问题,我会在这里添加解决方案。
对于开发环境向您的应用添加 debug=True
参数
app.run(debug=True)
如果您的开发环境在应用程序服务器上运行,那么您应该寻找自动重新加载选项。在uWSGI中有py-auto-reload例如。
对于已发布的稳定环境,您应该重新启动应用程序服务器。
例如在uWSGI中
There are several ways to make uWSGI gracefully restart.
# using kill to send the signal kill -HUP `cat /tmp/project-master.pid` # or the convenience option --reload uwsgi --reload /tmp/project-master.pid # or if uwsgi was started with touch-reload=/tmp/somefile touch /tmp/somefile
更多:http://uwsgi-docs.readthedocs.io/en/latest/Management.html#reloading-the-server
警告:如果您将应用程序和 Web 服务器(例如 uWSGI 和 Nginx)组合在一起,则重新启动 Nginx 将不会重新加载您的应用程序代码。重点关注应用服务器。
关于python - Flask __init__.py 不显示更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41376287/