使用uWSGI运行应用程序时需要Flask吗? [英] Is Flask required when running an application with uWSGI?

查看:63
本文介绍了使用uWSGI运行应用程序时需要Flask吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习使用Flask运行Web应用程序.许多指南描述了如何使用uWSGI作为服务器来运行Flask应用程序.如果uWSGI可以运行该应用程序,还需要Flask吗?

I am learning about using Flask for running a web application. Many guides describe how to use uWSGI as a server to run a Flask app. If uWSGI can run the application, is Flask still required along with it?

推荐答案

Flask不运行应用程序,它.uWSGI运行诸如使用Flask创建的应用程序.不需要Flask,但是需要 some 应用程序.

Flask doesn't run an application, it is the application. uWSGI runs applications such as those created with Flask. Flask isn't required, but some application is.

WSGI是 PEP 3333 中定义的标准,该标准描述了HTTP如何服务器与Python应用程序对话.uWSGI实现WSGI的服务器端.Flask是用于创建实现WSGI应用程序端的程序的框架.

WSGI is a standard defined in PEP 3333 that describes how a HTTP server talks to a Python application. uWSGI implements the server side of WSGI. Flask is a framework for creating programs that implements the application side of WSGI.

鉴于WSGI是已记录的标准,因此创建WSGI应用程序不需要Flask.uWSGI没有实现应用程序端,因此您仍将编写一个与之分离的应用程序,并使用uWSGI来提供服务.可以使用任何其他WSGI框架,也可以手动实现.

Given that WSGI is a documented standard, Flask is not required for creating a WSGI application. uWSGI does not implement the application side, so you would still write an application separate from it and use uWSGI to serve that. Any other WSGI framework could be used, or it could be implemented manually.

最基本的WSGI应用程序是可调用程序,它采用 environ dict和 start_response 函数,对该dict中的数据进行操作,调用 start_response (带有状态和标头),然后返回响应的正文.例如,uWSGI可以同时服务于Flask应用程序.

At its most basic a WSGI application is a callable that takes an environ dict and start_response function, acts on the data in the dict, calls start_response with status and headers, then returns the body of the response. For example, uWSGI could serve this just as well as it could serve a Flask application.

def basic_application(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/plain')])
    return b'Hello, World!'

从PEP:

这不应解释为意味着应用程序开发人员将使用WSGI作为Web编程API!假定应用程序开发人员将继续使用现有的高级框架服务来开发其应用程序.WSGI是面向框架和服务器开发人员的工具,并不旨在直接支持应用程序开发人员.

this should not be construed to mean that application developers will use WSGI as a web programming API! It is assumed that application developers will continue to use existing, high-level framework services to develop their applications. WSGI is a tool for framework and server developers, and is not intended to directly support application developers.

虽然有可能做到,但不建议这样做.有太多事情(请参阅PEP)很难正确解决,并且不是什么特别有趣或易于实现的事情,而这需要编写比上面的示例更强大的功能.这就是为什么存在诸如Flask之类的框架的原因.

While it is possible to do, it is not advised. There are too many things (see the PEP) that are difficult to get right and not particularly interesting or easy to implement that would be required to write anything more powerful than the example above. Which is why frameworks like Flask exist.

这篇关于使用uWSGI运行应用程序时需要Flask吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆