2010-09-30 80 views
2

我遇到了讓我的Mod Python正常工作的問題。mod_python Apache配置

我按照mod_python的手動發現here

因此,這裏是我的Apache安裝(我用虛擬主機):

<VirtualHost *:80> 
    ServerName hostname 
    DocumentRoot "C:/Documents and Settings/username/hostname/www" 

    <Directory "C:/Documents and Settings/username/hostname"> 
     DirectoryIndex index.py 
     AddHandler mod_python .py 
     PythonHandler www.index 
     PythonDebug On 
    </Directory> 
</VirtualHost> 

這裏是我的處理程序index.py:

from mod_python import apache 

def handler(req): 
    req.content_type = "text\plain" 
    req.write("Hello World!") 
    return apache.OK 

完成設置後,出現以下錯誤:

ImportError: No module named www.index 

注:我加入萬維網索引究其原因,是因爲這是mod_python的教程中指出:

Attempt to import a module by name myscript. (Note that if myscript was in a subdirectory of the directory where PythonHandler was specified, then the import would not work because said subdirectory would not be in the sys.path. One way around this is to use package notation, e.g. "PythonHandler subdir.myscript".)

如果我使用mod_python.publisher作爲我PythonHandler,一切工作正常。不知道我在這裏錯過了什麼。

回答

0

如果您可以停止使用mod_python,因爲它現在被放棄了。 mod_wsgi是要走的路。

+1

你不回答OP的問題 – joaquin 2010-09-30 14:21:07

+4

是的,他很好。 Lark只是遵循mod_python教程,所以將他指向mod_wsgi併爲他節省一些頭髮非常重要。 – 2010-09-30 14:34:21

+0

這個答案不是答案,但它是相關的信息。作爲對原文的評論,它可能會更好。 – ddoxey 2015-03-19 17:08:18

1

我想通了。我的目錄與我的DocumentRoot不匹配。

我讚賞有關mod_wsgi的回覆。我最終將遷移到wsgi,但我仍然在學習如何使用Python進行Web開發,並且我基本上默認學習使用mod_python。

+0

不好的選擇。現在切換,以便您可以專注於Web開發,而不是管理沒有太多用處的產品。 – 2010-09-30 15:28:14