This question likely betrays a misconception, but I'm curious what the "Tomcat" of the Python world is.
这个问题很可能背叛了一个误解,但我很好奇Python世界的“Tomcat”是什么。
All of my web programming experience is in Java (or Groovy) so I think in Java terms. And when I think of making a basic web-app, I think of writing some servlets, building a WAR file, and deploying it in Tomcat or another servlet container.
我的所有Web编程经验都是Java(或Groovy),所以我认为用Java术语来说。当我想要创建一个基本的Web应用程序时,我想到编写一些servlet,构建一个WAR文件,并将它部署在Tomcat或另一个servlet容器中。
In Python, suppose I wrote some code that was capable of responding to HTTP requests, what would I do with it? How would I deploy it?
在Python中,假设我编写了一些能够响应HTTP请求的代码,我该怎么办呢?我该如何部署它?
Specifically: What is the most commonly used container in Python? And is there an equivalent of a WAR file, a standard packaging of a web-app into one file that works in the various containers?
具体来说:Python中最常用的容器是什么?是否有一个等效的WAR文件,一个web-app的标准包装到一个文件中,可以在各种容器中运行?
4 个解决方案
#1
28
There are different approaches which have one thing in common: They usually communicate via WSGI with their "container" (the server receiving the HTTP requests before they go to your Python code).
有不同的方法有一个共同点:它们通常通过WSGI与它们的“容器”(服务器在转到Python代码之前接收HTTP请求)进行通信。
There are various containers:
有各种容器:
- wsgiref - a very simple reference implementation which is nice during development
- wsgiref - 一个非常简单的参考实现,在开发过程中很好
- Apache with mod_wsgi
- Apache与mod_wsgi
- most other Webservers with a module adding WSGI support
- 大多数其他Web服务器都带有一个添加WSGI支持的模块
- many more
- 还有很多
#2
5
when I think of making a basic web-app, I think of writing some servlets, building a WAR file, and deploying it in Tomcat or another servlet container.
当我想要创建一个基本的Web应用程序时,我想到编写一些servlet,构建一个WAR文件,并将它部署在Tomcat或其他servlet容器中。
That's nice, but irrelevant. That's just a Java-ism, and doesn't apply very widely outside Java.
这很好,但无关紧要。这只是一个Java主义,并不适用于Java以外的广泛应用。
In Python, suppose I wrote some code that was capable of responding to HTTP requests, what would I do with it? How would I deploy it?
在Python中,假设我编写了一些能够响应HTTP请求的代码,我该怎么办呢?我该如何部署它?
That depends.
那要看。
What is the most commonly used container in Python?
Python中最常用的容器是什么?
There isn't one.
没有一个。
And is there an equivalent of a WAR file, a standard packaging of a web-app into one file that works in the various containers?
是否有一个等效的WAR文件,一个web-app的标准包装到一个文件中,可以在各种容器中运行?
There isn't one.
没有一个。
HTTP is a protocol for producing a response to a request. That's it. It's really a very small thing.
HTTP是用于生成对请求的响应的协议。而已。这真的是一件非常小的事情。
You have CGI scripts which can respond to a request. The Python cgi
library can do that. http://docs.python.org/library/cgi.html.
您有可以响应请求的CGI脚本。 Python cgi库可以做到这一点。 http://docs.python.org/library/cgi.html。
This is relatively inefficient because the simple CGI rule is "fire off a new process for each request." It can also be insecure if the script allows elevated privileges or badly planned-out uploads.
这是相对低效的,因为简单的CGI规则是“为每个请求启动一个新进程”。如果脚本允许提升权限或严格计划的上载,也可能不安全。
You have the mod_wsgi
framework to connect Apache to Python. This can behave like CGI, or it can have a dedicated Python "daemon" running at the end of a named pipe.
你有mod_wsgi框架将Apache连接到Python。这可以像CGI一样,或者它可以在命名管道的末尾运行一个专用的Python“守护进程”。
The WSGI standard defines a format for request and response processing that's very handy and very extensible. Most of the frameworks -- in one way or another -- are WSGI compatible.
WSGI标准定义了一种非常方便且可扩展的请求和响应处理格式。大多数框架 - 以某种方式 - 与WSGI兼容。
Finally, there are more complete frameworks that include class definitions for requests and responses, URL parsing, Authentication, Authorization, etc., etc.
最后,还有更完整的框架,包括请求和响应的类定义,URL解析,身份验证,授权等等。
Here's a list: http://wiki.python.org/moin/WebFrameworks
这是一个列表:http://wiki.python.org/moin/WebFrameworks
#3
2
Maybe 'uwsgi' will help. Here is the link:http://projects.unbit.it/uwsgi/
也许'uwsgi'会有所帮助。这是链接:http://projects.unbit.it/uwsgi/
#4
0
There are many web-servers available for python. Some of the webservers like CherryPy was written in Python itself. The most coolest part of the answer is that tomcat server itself support Python-based applications.
有许多web服务器可用于python。像CherryPy这样的一些Web服务器是用Python编写的。答案中最酷的部分是tomcat服务器本身支持基于Python的应用程序。
For further details look into this site: https://wiki.python.org/moin/WebServers
有关详细信息,请访问此站点:https://wiki.python.org/moin/WebServers
#1
28
There are different approaches which have one thing in common: They usually communicate via WSGI with their "container" (the server receiving the HTTP requests before they go to your Python code).
有不同的方法有一个共同点:它们通常通过WSGI与它们的“容器”(服务器在转到Python代码之前接收HTTP请求)进行通信。
There are various containers:
有各种容器:
- wsgiref - a very simple reference implementation which is nice during development
- wsgiref - 一个非常简单的参考实现,在开发过程中很好
- Apache with mod_wsgi
- Apache与mod_wsgi
- most other Webservers with a module adding WSGI support
- 大多数其他Web服务器都带有一个添加WSGI支持的模块
- many more
- 还有很多
#2
5
when I think of making a basic web-app, I think of writing some servlets, building a WAR file, and deploying it in Tomcat or another servlet container.
当我想要创建一个基本的Web应用程序时,我想到编写一些servlet,构建一个WAR文件,并将它部署在Tomcat或其他servlet容器中。
That's nice, but irrelevant. That's just a Java-ism, and doesn't apply very widely outside Java.
这很好,但无关紧要。这只是一个Java主义,并不适用于Java以外的广泛应用。
In Python, suppose I wrote some code that was capable of responding to HTTP requests, what would I do with it? How would I deploy it?
在Python中,假设我编写了一些能够响应HTTP请求的代码,我该怎么办呢?我该如何部署它?
That depends.
那要看。
What is the most commonly used container in Python?
Python中最常用的容器是什么?
There isn't one.
没有一个。
And is there an equivalent of a WAR file, a standard packaging of a web-app into one file that works in the various containers?
是否有一个等效的WAR文件,一个web-app的标准包装到一个文件中,可以在各种容器中运行?
There isn't one.
没有一个。
HTTP is a protocol for producing a response to a request. That's it. It's really a very small thing.
HTTP是用于生成对请求的响应的协议。而已。这真的是一件非常小的事情。
You have CGI scripts which can respond to a request. The Python cgi
library can do that. http://docs.python.org/library/cgi.html.
您有可以响应请求的CGI脚本。 Python cgi库可以做到这一点。 http://docs.python.org/library/cgi.html。
This is relatively inefficient because the simple CGI rule is "fire off a new process for each request." It can also be insecure if the script allows elevated privileges or badly planned-out uploads.
这是相对低效的,因为简单的CGI规则是“为每个请求启动一个新进程”。如果脚本允许提升权限或严格计划的上载,也可能不安全。
You have the mod_wsgi
framework to connect Apache to Python. This can behave like CGI, or it can have a dedicated Python "daemon" running at the end of a named pipe.
你有mod_wsgi框架将Apache连接到Python。这可以像CGI一样,或者它可以在命名管道的末尾运行一个专用的Python“守护进程”。
The WSGI standard defines a format for request and response processing that's very handy and very extensible. Most of the frameworks -- in one way or another -- are WSGI compatible.
WSGI标准定义了一种非常方便且可扩展的请求和响应处理格式。大多数框架 - 以某种方式 - 与WSGI兼容。
Finally, there are more complete frameworks that include class definitions for requests and responses, URL parsing, Authentication, Authorization, etc., etc.
最后,还有更完整的框架,包括请求和响应的类定义,URL解析,身份验证,授权等等。
Here's a list: http://wiki.python.org/moin/WebFrameworks
这是一个列表:http://wiki.python.org/moin/WebFrameworks
#3
2
Maybe 'uwsgi' will help. Here is the link:http://projects.unbit.it/uwsgi/
也许'uwsgi'会有所帮助。这是链接:http://projects.unbit.it/uwsgi/
#4
0
There are many web-servers available for python. Some of the webservers like CherryPy was written in Python itself. The most coolest part of the answer is that tomcat server itself support Python-based applications.
有许多web服务器可用于python。像CherryPy这样的一些Web服务器是用Python编写的。答案中最酷的部分是tomcat服务器本身支持基于Python的应用程序。
For further details look into this site: https://wiki.python.org/moin/WebServers
有关详细信息,请访问此站点:https://wiki.python.org/moin/WebServers