サーバーによっては、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"
ちょっと表示してみましょう。
#!/usr/local/bin/python
print "Content-Type: text/html\n"
print "<title>Python CGI sample 02</title>"
print "<p>簡単なHTML文書</p>"
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>"