2010-03-29 41 views
3

我編輯這個問題後,我找到了解決方案...我需要了解爲什麼解決方案的工作,而不是我的方法?蟒蛇上的Apache - 越來越404

這可能是一個愚蠢的問題。我試圖尋找其他相關的問題......但無濟於事。

我運行的Apache/2.2.11(Ubuntu的)DAV/2 SVN/1.5.4 PHP/5.2.6-3ubuntu4.5用了Suhosin貼片的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錯誤。

我在想什麼?

我用這個資源在apache上啓用python解析。 http://ubuntuforums.org/showthread.php?t=91101

從同一個線程...下面的代碼工作.. 爲什麼? #!的/ usr/bin中/ Python的

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 

回答

4

我想的mod_python的Publisher Handler期待找到test.py. index功能

您可以通過將test.py內的任何函數放入URL的末尾來調用它。如果沒有給出,則默認功能是index

+0

看起來像是答案!謝謝。我會盡快接受stackoverflow允許。 – Kirby 2010-03-29 19:09:37

0

如果您希望您的代碼是否正常工作,你還可以配置你的Web服務器來處理特等爲CGI腳本,而不是在Apache的配置使用mod_python.publisher

AddHandler cgi-script .py 

如果你不想要錯誤403,編輯:

<Directory /path/to/www/yourfile.py> 
Options +ExecCGI 
</Directory>