Flask at First Run: Do Not Use the Development Server in a Production Environment

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



Leave a reply



Submit