如何使用Python的CGI编程编写第一个Hello World程序?

如何使用Python的CGI编程编写第一个Hello World程序?

更多Python相关文章,请阅读:Python 教程

第一个CGI程序

位于/var/www/cgi-bin目录中的CGI脚本称为hello.py,其内容如下。在运行CGI程序之前,我们通过使用chmod 755 hello.py UNIX命令更改文件模式,以使文件可执行。

示例

#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'

输出

如果单击hello.py,则会生成以下输出 −

Hello Word! This is my first CGI program

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程