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)
And I get this message:
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/
Why am I getting this error when I run Flask?
A previous version of the message read "Do not use the development server in a production environment."
The official tutorial discusses deploying an app to production. One option is to use Waitress, a production WSGI server. Other servers include Gunicorn and uWSGI.
When running publicly rather than in development, you should not use the built-in development server (
flask run). The development server is provided by Werkzeug for convenience, but is not designed to be particularly efficient, stable, or secure.
Instead, use a production WSGI server. For example, to use Waitress, first install it in the virtual environment:
$ pip install waitress
You need to tell Waitress about your application, but it doesn’t use
FLASK_APPlike flask run does. You need to tell it to import and call the application factory to get an application object.
$ waitress-serve --call 'flaskr:create_app' Serving on http://0.0.0.0:8080
Or you can use
waitress.serve() in the code instead of using the CLI command.
from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "<h1>Hello!</h1>" if __name__ == "__main__": from waitress import serve serve(app, host="0.0.0.0", port=8080)
$ python hello.py
If for some people (like me earlier) the above answers don't work, I think the following answer would work (for Mac users I think) Enter the following commands to do flask run
$ export FLASK_APP = hello.py $ export FLASK_ENV = development $ flask run
Alternatively you can do the following (I haven't tried this but one resource online talks about it)
$ export FLASK_APP = hello.py $ python -m flask run
source: For more
When running the python file, you would normally do this
This will display these messages.
To avoid these messsages. Inside the CLI (Command Line Interface), run these commands.
export FLASK_APP=app.py export FLASK_RUN_HOST=127.0.0.1 export FLASK_ENV=development export FLASK_DEBUG=0 flask run
This should work perfectlly. :) :)