且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运行python脚本作为CGI Apache服务器

更新时间:2023-10-21 15:45:10

我觉得你失踪后

print("Content-type: text/html")

CGI脚本的输出应该包括两个部分,一个空行隔开。第一部分包含了一些头,告诉客户什么样的数据是
以下内容。

The output of a CGI script should consist of two sections, separated by a blank line. The first section contains a number of headers, telling the client what kind of data is following.

第二部分一般是HTML,它允许客户端软件,以显示与标题,在线图像很好地格式化文本,等等。

The second section is usually HTML, which allows the client software to display nicely formatted text with header, in-line images, etc.

这可能看起来像

#!/usr/bin/env python

print "Content-Type: text/html"
print
print """
    <TITLE>CGI script ! Python</TITLE>
    <H1>This is my first CGI script</H1>
    Hello, world!
"""

有关更多详情,请访问蟒蛇-CGI

For more details visit python-cgi

有关python3

#!/usr/bin/env python3

print("Content-Type: text/html")
print()
print ("""
    <TITLE>CGI script ! Python</TITLE>
    <H1>This is my first CGI script</H1>
    Hello, world!
"""
)