Apache mod_wsgi 错误

Apache mod_wsgi 错误

我已按照本指南在 cpanel 服务器(CentOS 5.2)上设置 django http://toic.org/2010/08/14/django-on-cpanel-with-python2-6-virtualenv-and-mod_wsgi/评论页-1/#评论-680 我在我设置的域名上获得了 500 个页面。

Apache 日志:

 File "/home/myofirst/virtualenv/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/handlers/wsgi.py", line 1, in <module>
 File "/home/myofirst/djangosites/test1.wsgi", line 13, in <module>
 mod_wsgi (pid=20251): Exception occurred processing WSGI script '/home/myofirst/djangosites/test1.wsgi'.
 mod_wsgi (pid=20251): Target WSGI script '/home/myofirst/djangosites/test1.wsgi' cannot be loaded as Python module.

WSGI 文件:

import sys
import site
import os

vepath = '/home/myofirst/virtualenv/lib/python2.6/site-packages'
prev_sys_path = list(sys.path)
site.addsitedir(vepath)
sys.path.append('/home/myofirst/djangosites')
new_sys_path = [p for p in sys.path if p not in prev_sys_path]
for item in new_sys_path:
    sys.path.remove(item)
sys.path[:0] = new_sys_path
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'test1.settings'
application = WSGIHandler()

这一行好像崩溃了:

from django.core.handlers.wsgi import WSGIHandler

Virtualenv 路径是正确的,所以我不确定是什么原因导致的。

编辑运行 .wsgi 文件时我得到了这个回溯。

Traceback (most recent call last):
  File "djangosites/test1.wsgi", line 14, in <module>
    from django.core.handlers.wsgi import WSGIHandler
  File "/home/myofirst/virtualenv/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/handlers/wsgi.py", line 1, in <module>
    from threading import Lock
  File "/opt/python2.6/lib/python2.6/threading.py", line 13, in <module>
    from functools import wraps
ImportError: cannot import name wraps

答案1

__init__.py同一文件夹中是否有文件test1.wsgi

答案2

我在 apache conf 文件中进行了更改LogLevel warn 。DjangoLogLevel debug现在可以加载,日志中没有错误,只有几行指示已启动 python 进程的位置。

我猜隐藏错误并不是一个好主意,但我希望调试能记录更多错误。无论如何它都有效,这才是最重要的。

相关内容