Python 中的嵌入式 Web 服务器?

发布于 2024-07-08 11:29:05 字数 1560 浏览 24 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

国粹 2024-07-15 11:29:05

有多简约以及目的是什么?

SimpleHTTPServer 作为标准 Python 库的一部分免费提供。

如果您需要更多功能,请查看 CherryPy 或(在顶部)扭曲

How minimalistic and for what purpose?

SimpleHTTPServer comes free as part of the standard Python libraries.

If you need more features, look into CherryPy or (at the top end) Twisted.

独自唱情﹋歌 2024-07-15 11:29:05

我正在成为新发布的 Circuits 库的忠实粉丝。 它是一个组件/事件框架,附带一组非常好的软件包,用于创建 Web 服务器和应用程序。 应用。 下面是来自该站点的简单 Web 示例:

from circuits.lib.web import Server, Controller

class HelloWorld(Controller):
   def index(self):
      return "Hello World!"

server = Server(8000)
server += HelloWorld()
server.run()

它的 WSGI 支持也并不比这更复杂。 好东西。

I'm becoming a big fan of the newly released circuits library. It's a component/event framework that comes with a very nice set of packages for creating web servers & apps. Here's the simple web example from the site:

from circuits.lib.web import Server, Controller

class HelloWorld(Controller):
   def index(self):
      return "Hello World!"

server = Server(8000)
server += HelloWorld()
server.run()

Its WSGI support is no more complicated than that, either. Good stuff.

疯了 2024-07-15 11:29:05

如果您要做很​​多并发的事情,您可以考虑 KamaeliaHTTPServer

If you're doing a lot of concurrent stuff, you might consider Kamaelia's HTTPServer.

下雨或天晴 2024-07-15 11:29:05

我发现 web.py 非常容易使用: http://webpy.org/

I've found web.py pretty easy to use : http://webpy.org/

澉约 2024-07-15 11:29:05

如果您想使用标准库中的某些内容,我强烈建议不要使用 SimpleHTTPServer,而是使用 wsgiref.simple_server。 SimpleHTTPServer 是一种笨拙且相当无意义的 Web 应用程序实现方式,虽然原始 WSGI 并不是很容易(但肯定是可能的),但您可以选择在其之上使用任何基于 WSGI 的框架。 另外,如果您使用 wsgiref,您稍后可以选择更改为像 CherryPy 这样的服务器(请注意,CherryPy 中的服务器可以与框架的其余部分分开使用,并且您只需要 一个文件仅用于服务器)。 对于“真正的”Web 应用程序,CherryPy 比 wsgiref 有几个优点,但对于本地托管的应用程序来说,这些优点都不重要。

如果您正在制作桌面应用程序,则需要为 wsgiref 或 CherryPy 启动单独的线程。 如果没问题,那么基于 WSGI 的服务器可能是最简单的。 如果您不想为服务器启动单独的线程,那么您很可能需要使用 Twisted。

If you want to use something from the standard library I would strongly recommend not using SimpleHTTPServer, but instead using wsgiref.simple_server. SimpleHTTPServer is awkward and a rather nonsensical way to implement a web application, and while raw WSGI isn't terribly easy (but certainly possible), you have the option to use any WSGI-based framework on top of it. Also if you use wsgiref you will have the option to change to a server like CherryPy later (note that the server in CherryPy can be used separately from the rest of the framework, and you only need one file for just the server). For a "real" web application CherryPy has several advantages over wsgiref, but for a locally hosted application it's unlikely any of them will matter.

If you are making a desktop application you will need to launch a separate thread for either wsgiref or CherryPy. If that's fine, then a WSGI-based server would probably be easiest. If you don't want to launch a separate thread for the server then you most likely need to use Twisted.

岛歌少女 2024-07-15 11:29:05

请参阅 WSGI 参考实现。

See the WSGI reference implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文