Flask at first run: Do not use the development server in a production environment
As of Flask 2.2, the development server always shows this warning, it is not possible to disable it. The development server is not intended for use in production. It is not designed to be particularly efficient, stable, or secure. Use a production WSGI server instead. See the deployment docs from Flask for more information.
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.
That warning applies to the development server, not Flask itself. The Flask framework is appropriate for any type of application and deployment.
Why should I switch to a flask production deployment instead of a development server?
To answer your 'main question', as the Flask documentation outlines:
Flask’s built-in server is not suitable for production as it doesn’t scale well.
This will not be apparent to you on Heroku if you're the only person using the application, but as more and more users visit your app, the Flask server will not handle this well (it is not designed to, versus something like Gunicorn).
The 'environment' string to which you are referring is actually a configuration setting that allows you to tell the application how to behave. For example, by setting the environment to 'development' (i.e. export FLASK_ENV=development
), you will get certain behaviours from the application and any extensions that you would not want in production, e.g. interactive debug when an error is thrown. If it is set to 'production', you will not get these behaviours.
There is no real contradiction here: the app isn't configured to run locally as 'development', which is unrelated to the use of the flask development server.
The flask documentation is superb, so I would recommend you look there to understand how flask works. Also take a look at Miguel Grinberg's excellent Flask Mega Tutorial series.
python flask to production server
By default, app.run()
hosts server on localhost(127.0.0.1). To make it accessible,
app.run('0.0.0.0', port=5000)
Although, the server bundled with Flask is not for production, it is recommended to use WSGI server(mod_wsgi, nginx, gunicorn, etc.)
https://flask.palletsprojects.com/en/1.0.x/deploying/wsgi-standalone/
Related Topics
Runtimeerror: Main Thread Is Not in Main Loop
Retrieving a Foreign Key Value with Django-Rest-Framework Serializers
Matplotlib Savefig() Plots Different from Show()
Django Return Redirect() with Parameters
How Does _Contains_ Work for Ndarrays
Functions That Help to Understand JSON(Dict) Structure
Python: Call a Function from String Name
Getting the SQL from a Django Queryset
How to Make Urllib2 Requests Through Tor in Python
How to Group a List of Tuples/Objects by Similar Index/Attribute in Python
How to Specify an Authenticated Proxy for a Python Http Connection
Imports in _Init_.Py and 'Import As' Statement
Fastest Way to Take a Screenshot with Python on Windows