2013-04-30 49 views
1

我已经安装了Python并在apache中进行了配置。我创建了一个Python网页文件,并在浏览器中打开这个文件,我得到一个错误。但是相同的代码在命令行中工作。我希望问题来自我的apache配置。python网页上的错误

这是错误消息。

MOD_PYTHON ERROR 

ProcessId:  6368 
Interpreter: 'localhost' 

ServerName:  'localhost' 
DocumentRoot: '/var/www' 

URI:   '/python_test/hello_world.py' 
Location:  None 
Directory:  '/var/www/' 
Filename:  '/var/www/python_test/hello_world.py' 
PathInfo:  '' 

Phase:   'PythonHandler' 
Handler:  'mod_python.py' 

Traceback (most recent call last): 

    File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch 
    default=default_handler, arg=req, silent=hlist.silent) 

    File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 1202, in _process_target 
    module = import_module(module_name, path=path) 

    File "/usr/lib/python2.7/dist-packages/mod_python/importer.py", line 304, in import_module 
    return __import__(module_name, {}, {}, ['*']) 

ImportError: No module named py 

我的Python代码是:

print "Hello world!" 


My httpd.conf file is : 

ServerName localhost 
<Directory /var/www/> 
     Options Indexes FollowSymlinks MultiViews 
     AllowOverride AuthConfig 
     order allow,deny 
     allow from all 

     AddHandler mod_python .py 
     PythonHandler mod_python.py 
     PythonDebug On 

</Directory> 
+1

为什么啊,为什么你还在使用[死多头的mod_python](http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html)? – Matthias 2013-04-30 15:11:36

回答

3

AddHandler需要广告ditional参数,你基本上提供它与python扩展.py。然后,您将Python文件的名称提供给没有扩展名的PythonHandler

AddHandler cgi-script .py 
PythonHandler mod_python 
PythonDebug On 
+0

非常感谢!它的工作正常。 – vellaidurai 2013-04-30 15:14:19

+0

不用担心@vellaidurai。如果工作正常,欢迎将答案标记为已接受。 – eandersson 2013-04-30 15:17:03

+0

我接受了这个。谢谢。 – vellaidurai 2013-04-30 15:19:49

0

你写道:

AddHandler mod_python .py 

尝试将.py

编辑之前删除空白:

好了,试试这样的事情:

SetHandler python-program 
PythonHandler mod_python.py 
PythonDebug On 

或以下:

AddHandler mod_python py 
PythonHandler mod_python.py 
PythonDebug On 
+0

感谢您的回复,当我删除空间并尝试重新启动Apache。它引发以下错误。 AddHandler至少需要两个参数,一个处理程序名称后跟一个或多个文件扩展名 – vellaidurai 2013-04-30 14:44:34

+0

Thanks..its fixed。 – vellaidurai 2013-04-30 15:22:24

1

似乎有一个错字在httpd.conf AddHandler mod_python .py

因为它是空间寻找两个模块mod_pythonpy

+0

感谢您的回复,当我删除空间并尝试重新启动Apache。它引发以下错误。 AddHandler至少需要两个参数,一个处理程序名称后跟一个或多个文件扩展名 – vellaidurai 2013-04-30 14:43:50