有哪些学习 Python CGI 编程的好资源?

发布于 2024-07-08 06:31:43 字数 1557 浏览 4 评论 0原文

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

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

发布评论

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

评论(3

忆梦 2024-07-15 06:31:43

CGI 编程最大的资源之一是 CGI 主页。 完成后,请熟悉 cgicgitb 模块应该是您的下一个任务。

但不要忽视学习 WSGI (libref) 并使用 CGI 到 WSGI 适配器,例如 失败

One of the biggest resources for CGI programming is the CGI homepage. Once you're done with that, familiarizing yourself with the cgi and cgitb modules should be your next task.

But don't discount learning WSGI (libref) and using a CGI-to-WSGI adaptor such as flup.

罗罗贝儿 2024-07-15 06:31:43

我不明白的是为什么你坚持使用 CGI,因为这是一个通用网关接口,旨在与像 apache 这样的网络服务器结合使用,而你的设备上肯定没有。

我建议您使用 wsgiref.simple_server 这是一个单一的python 2.5 及更高版本附带线程内置网络服务器(如果您有 2.4 或更低版本,您可以 d/ l 来自pypi的wsgiref,它是一个纯python包)。 这样您还可以避开混乱的 CGI 编程并编写 wsgi 应用程序:

from wsgiref.simple_server import make_server

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

httpd = make_server('', 8000, application)
httpd.serve_forever()

What I don't understand is why you insist on CGI, because that's a Common Gateway Interface meant to be used in conjunction with a webserver like apache, which you surely do not have on that device.

I would suggest you use wsgiref.simple_server which is a single threaded buildin webserver shipped with python 2.5 and up (if you have 2.4 or below you can d/l wsgiref from pypi, it is a pure python package). That way you can also sidestep messy CGI programming and write a wsgi application:

from wsgiref.simple_server import make_server

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

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