flask应用运行提示-不要在产品环境使用开发服务

  • 作者:泛逸舟
  • 时间:
  • 520人已阅读

I installed 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)

And I get this message:

WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead

Restarting with stat
* Debugger is active!
* Debugger PIN: 138-642-273
* Running on http://127.0.0.1:5000/

When I come to http://127.0.0.1:5000 it says: "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again."

 

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.

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

export FLASK_ENV=development
flask run

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

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.

Top