While I am running Flask code from my command line, a warning is appearing:
Serving Flask app \"hello_flask\" (lazy loading)
* Environment: production
WARN
I was typing flask run and then saw this message after that I solve this issue with these:
1- Add this text in your myproject/.flaskenv :
FLASK_APP=myapp.py
FLASK_ENV=development
also you should type "pip3 install python-dotenv" for using this file .flaskenv
2-in your project folder type in terminal your flask command which one you use :
flask-3 run
As of Flask 1.x, the default environment is set to production.
To use the development environment, create a file called .flaskenv
and save it in the top-level (root) of your project directory. Set the FLASK_ENV=development
in the .flaskenv
file. You can also save the FLASK_APP=myapp.py
.
Example:
myproject/.flaskenv
:
FLASK_APP=myapp.py
FLASK_ENV=development
Then you just execute this on the command line:
flask run
That should take care of the warning.
As stated in the Flask documentation:
While lightweight and easy to use, Flask’s built-in server is not suitable for production as it doesn’t scale well and by default serves only one request at a time.
Given that a web application is expected to handle multiple concurrent requests from multiple users, Flask is warning you that the development server will not do this (by default). It recommends using a Web Server Gateway Interface (WSGI) server (numerous possibilities are listed in the deployment docs with further instructions for each) that will function as your web/application server and call Flask as it serves requests.