Я отредактировал этот вопрос после того, как нашел решение ... Мне нужно понять, почему решение работает вместо моего метода?
Это, вероятно, глупый вопрос. Я пытался найти другие вопросы, которые связаны ... но безрезультатно.
Я использую Apache / 2.2.11 (Ubuntu) DAV / 2 SVN / 1.5.4 PHP / 5.2.6-3ubuntu4.5 с Suhosin-Patch mod_python / 3.3.1 Python / 2.6.2
У меня есть скрипт с именем test.py
#! /usr/bin/python
print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
print "hello world"
запуск его как исполняемого файла работает ...
/var/www$ ./test.py
Content-Type: text/html
hello world
при запуске http://localhost/test.py я получаю ошибку 404.
Чего мне не хватает?
я использовал этот ресурс, чтобы включить синтаксический анализ python на apache. http://ubuntuforums.org/showthread.php?t=91101
Из того же потока ... работал следующий код .. почему?
#! / USR / бен / питон
import sys
import time
def index(req):
# Following line causes error to be sent to browser
# rather than to log file (great for debug!)
sys.stderr = sys.stdout
#print "Content-type: text/html\n"
#print """
blah1 = """<html>
<head><title>A page from Python</title></head>
<body>
<h4>This page is generated by a Python script!</h4>
The current date and time is """
now = time.gmtime()
displaytime = time.strftime("%A %d %B %Y, %X",now)
#print displaytime,
blah1 += displaytime
#print """
blah1 += """
<hr>
Well House Consultants demonstration
</body>
</html>
"""
return blah1