初次运行时的烧瓶:请勿在生产环境中使用开发服务器 [英] Flask at first run: Do not use the development server in a production environment

查看:2776
本文介绍了初次运行时的烧瓶:请勿在生产环境中使用开发服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PyCharm社区版中安装了Flask插件,而我的烧瓶应用程序中只有以下简单代码:

I installed the Flask plugin in PyCharm Community Edition and I just have this simple code in my flask app:

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/

运行Flask时为什么会出现此错误?

Why am I getting this error when I run Flask?

该消息的先前版本显示为请勿在生产环境中使用开发服务器."

推荐答案

除非您告知开发服务器它正在开发模式下运行,否则它将假定您正在生产环境中使用它,并警告您不要这样做. 开发服务器不适用于生产环境.它的设计目的不是特别高效,稳定或安全.

Unless you tell the development server that it's running in development mode, it will assume you're using it in production and warn you not to. The development server is not intended for use in production. It is not designed to be particularly efficient, stable, or secure.

通过将FLASK_ENV环境变量设置为development来启用开发模式.

Enable development mode by setting the FLASK_ENV environment variable to development.

export FLASK_ENV=development
flask run

如果您在PyCharm(或可能是其他任何IDE)中运行,则可以在运行配置中设置环境变量.

If you're running in PyCharm (or probably any other IDE) you can set environment variables in the run configuration.

开发模式默认情况下启用调试器和重新加载器.如果不需要这些,请将--no-debugger--no-reloader传递给run命令.

Development mode enables the debugger and reloader by default. If you don't want these, pass --no-debugger or --no-reloader to the run command.

该警告不过是警告,并不是阻止您的应用运行的错误.如果您的应用无法正常运行,则您的代码还有其他问题.

That warning is just a warning though, it's not an error preventing your app from running. If your app isn't working, there's something else wrong with your code.

这篇关于初次运行时的烧瓶:请勿在生产环境中使用开发服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆