简体   繁体   English

为什么我应该切换到 flask 生产部署而不是开发服务器?

[英]Why should I switch to a flask production deployment instead of a development server?

I'm working on a flask app: https://github.com/josephmalisov/todo_list When I run it on computer, I am told (with the warning in red):我正在开发 flask 应用程序: https://github.com/josephmalisov/todo_list当我在计算机上运行它时,我被告知(带有红色警告):

Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.

First of all, isn't that contradictory?首先,这不是矛盾吗?

But mainly, I want to know the difference between a development server and production deployment.但主要是,我想知道开发服务器和生产部署之间的区别。 When I run it on heroku, it works, so what's the benefit of doing this lengthy flask tutorial of Deploy to Production ?当我在 heroku 上运行它时,它可以工作,那么做这个冗长的 flask部署到生产教程有什么好处?

To answer your 'main question', as the Flask documentation outlines:要回答您的“主要问题”,如 Flask 文档所述:

Flask's built-in server is not suitable for production as it doesn't scale well. Flask 的内置服务器不适合生产,因为它不能很好地扩展。

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).如果您是唯一使用该应用程序的人,则在 Heroku 上这对您来说不会很明显,但是随着越来越多的用户访问您的应用程序,Flask 服务器将无法很好地处理这个问题(与 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' (ie export FLASK_ENV=development ), you will get certain behaviours from the application and any extensions that you would not want in production, eg interactive debug when an error is thrown.例如,通过将环境设置为“开发”(即export FLASK_ENV=development ),您将从应用程序和任何您在生产中不需要的扩展获得某些行为,例如抛出错误时的交互式调试。 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.这里没有真正的矛盾:应用程序未配置为在本地作为“开发”运行,这与 flask 开发服务器的使用无关。

The flask documentation is superb, so I would recommend you look there to understand how flask works. flask 文档非常棒,因此我建议您查看那里以了解 flask 的工作原理。 Also take a look at Miguel Grinberg's excellent Flask Mega Tutorial series.还可以看看 Miguel Grinberg 的优秀 Flask 超级教程系列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python IIS 上的 Flask:警告:这是一个开发服务器。 不要在生产部署中使用它 - Python Flask on IIS: WARNING: This is a development server. Do not use it in a production deployment Flask服务器事件在开发中工作但不在生产中 - Flask server events working in development but not in production flask上的开发和生产服务器中的不同链接前缀 - Different link prefix in development and production server on flask 使用内部werkzeug开发服务器进行烧瓶部署 - flask deployment using internal werkzeug development server 烧瓶生产开发模式 - flask production and development mode Flask 首次运行:请勿在生产环境中使用开发服务器 - Flask at first run: Do not use the development server in a production environment 为什么我的 Django 登录可以在开发服务器上运行而不是在生产服务器上运行? - Why does my Django login work on development server but not production server? python flask 到生产服务器 - python flask to production server 我应该如何使用 socketio 运行 Flask 服务器? - How should I run flask server with socketio? 为什么在生产环境中而不是开发环境中出现此UnicodeEncodeError? App Engine Python - Why am I getting this UnicodeEncodeError in production but not in development? App Engine Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM