step 10 CGI

サーバーによっては、PythonでのCGIを実行できます。

Perlと同じようなもので、拡張子をcgiにします。

お約束で、Content-Type: text/htmlの後に、改行2つ。print "Content-Type: text/html\n"でいいですね。

何も表示しない短いソースです。


#!/usr/local/bin/python
print "Content-Type: text/html\n"

samp_01

ちょっと表示してみましょう。


#!/usr/local/bin/python
print "Content-Type: text/html\n"
print "<title>Python CGI sample 02</title>"
print "<p>簡単なHTML文書</p>"

samp_02

Pythonの他の命令も使って見ましょう。


#!/usr/local/bin/python
print "Content-Type: text/html\n\n"
for i in range(5):
    if i==2:
        print "<p>two</p>"
    else:
        print "<p>",i,"</p>"

samp_03






管理人:人泣礼(hitonaki@starword.org)