无法解决sys路径错误;模块据说缺少

时间:2011-02-05 22:48:27

标签: python django apache wsgi middleware

我一直在抛出一个异常,说明没有安装模块。任何帮助将不胜感激。

我环顾四周,有人建议通过扩展sys路径以包含app目录来解决此错误。我非常确定的东西由WSGI文件中的sys.path指令处理:

import os, sys
sys.path.append('/home/osqa')
sys.path.append('/home/osqa/trunk')
os.environ['DJANGO_SETTINGS_MODULE'] = 'trunk.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

错误输出如下所示:

[info] mod_wsgi (pid=15737): Attach interpreter ''.
[info] mod_wsgi (pid=15737): Create interpreter 'trunk|'.
[info] [client 172.31.0.6] mod_wsgi (pid=15737, process='OSQA', application='trunk|'): 
Loading WSGI script '/home/osqa/trunk/apache/django.wsgi'.
[error] [client 172.31.0.6] mod_wsgi (pid=15737): Exception occurred processing WSGI 
script '/home/osqa/trunk/apache/django.wsgi'.
[error] [client 172.31.0.6] Traceback (most recent call last):
[error] [client 172.31.0.6]   File "/usr/lib/python2.6/site-
packages/django/core/handlers/wsgi.py", line 230, in __call__
[error] [client 172.31.0.6]     self.load_middleware()
[error] [client 172.31.0.6]   File "/usr/lib/python2.6/site-
packages/django/core/handlers/base.py", line 42, in load_middleware
[error] [client 172.31.0.6]     raise exceptions.ImproperlyConfigured('Error importing  
middleware %s: "%s"' % (mw_module, e))
[error] [client 172.31.0.6] ImproperlyConfigured: Error importing middleware  
forum.middleware.extended_user: "No module named markdown"

Apache Config看起来像这样:

WSGISocketPrefix run/wsgi
<VirtualHost *:80>
ServerAdmin xxx@xxx.com   
DocumentRoot /home/osqa/trunk
ServerName trunk   
CustomLog logs/osqa.access.log common   
ErrorLog logs/osqa.error.log
WSGIScriptAlias / /home/osqa/trunk/apache/django.wsgi
<Directory> /home/osqa/trunk/apache>
            Order deny,allow
            Allow from all
</Directory>

WSGIDaemonProcess OSQA
WSGIProcessGroup OSQA
Alias /m/ /home/osqa/trunk/forum/skins/     
<Directory /home/osqa/trunk/forum/skins>
            Order deny,allow
            Allow from all
</Directory>
Alias /upfiles/ /home/osqa/trunk/forum/upfiles/
    <Directory /home/osqa/trunk/forum/upfiles>
            Order deny,allow
            Allow from all
    </Directory></VirtualHost>

forum.middleware.extended_user看起来像这样:     来自django.contrib.auth.middleware import AuthenticationMiddleware     从django.contrib.auth导入logoutfrom forum.models.user导入AnonymousUser     来自forum.views.auth import forward_suspended_userimport logging

class ExtendedUser(AuthenticationMiddleware):
def process_request(self, request):
    super(ExtendedUser, self).process_request(request)
    if request.user.is_authenticated():           
     try:
            request.user = request.user.user
            if request.user.is_suspended():       
                user = request.user
                logout(request)
                return forward_suspended_user(request, user)
                return None            
                except Exception, e:               
                    import traceback
                    logging.error("Unable to convert auth_user %s to forum_user: \n%s" % (                           request.user.id, traceback.format_exc()
                    ))
    request.user = AnonymousUser()
    return None

1 个答案:

答案 0 :(得分:0)

你能发布这个抛出异常的中间件,以便我们可以确切地看到它试图导入的内容吗?

听起来它正在导入降价,并且降价不在您的路径上。通常,这将安装在您的site-packages目录中,而不是安装在项目内部。

尝试pip install markdown

更新:你说它肯定安装了。降价安装在哪里?