我在PyCharm社区版中安装了Flask插件,我的Flask应用程序中有一个简单的代码:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return '<h1>Hello!</h1>'
if __name__ == "__main__":
app.run(debug=True)
我收到一条信息:
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead
* Restarting with stat
* Debugger is active!
* Debugger PIN: 123-456-789
* Running on http://127.0.0.1:5000/
为什么我运行烧瓶时会出现这个错误?
消息的早期版本为“请勿在生产环境中使用开发服务器。”
除非您告诉开发服务器它正在开发模式下运行,否则它将假定您正在生产环境中使用它,并警告您不要使用它。The development server is not intended for use in production. It is not designed to be particularly efficient, stable, or secure.
通过将
FLASK_ENV
环境变量设置为development
,启用开发模式。如果您在PyCharm(或任何其他IDE)中运行,则可以在运行配置中设置环境变量。
默认情况下,开发模式启用调试器和重载程序。如果不需要这些,请将
--no-debugger
或--no-reloader
传递给run
命令。不过,这个警告只是一个警告,并不是阻止应用程序运行的错误。如果你的应用程序不工作,你的代码还有其他问题。
The official tutorial discusses deploying an app to production.一个选项是使用Waitress,一个生产WSGI服务器。其他服务器包括Gunicorn和uWSGI。
或者可以在代码中使用
waitress.serve()
,而不是使用CLI命令。相关问题 更多 >
编程相关推荐