虚拟环境中的WSGI无法工作

0 投票
1 回答
727 浏览
提问于 2025-05-01 14:23

我在使用bitnami的Django环境。

当不使用虚拟环境时,WSGI工作得很好。

但是我在根目录下安装了虚拟环境,使用的命令是sudo apt-get install,现在WSGI在虚拟环境项目中无法工作了。

我的Apache配置文件是:

Alias /static "/opt/bitnami/apps/live/lib/python2.7/site-packages/django/contrib/admin/static"

<Directory '/opt/bitnami/apps/live/lib/python2.7/site-packages/django/contrib'>
    <IfVersion < 2.3 >
    Order allow,deny
    Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
    Require all granted
    </IfVersion>
</Directory>

WSGIScriptAlias /search "/opt/bitnami/apps/run/live_cybrhome.wsgi"

<Directory '/opt/bitnami/apps/run'>
    <IfVersion < 2.3 >
    Order allow,deny
    Allow from all
    </IfVersion>
    <IfVersion >= 2.3>
    Require all granted
    </IfVersion>
</Directory>

我的WSGI文件是:

import os, sys
sys.path.append('/opt/bitnami/apps/live')
sys.path.append('/opt/bitnami/apps/live/cybrhome')
os.environ['DJANGO_SETTINGS_MODULE'] = 'cybrhome.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Apache的日志是:

mod_wsgi (进程ID=4070):处理WSGI脚本时发生异常 '/opt/bitnami/apps/run/live_cybrhome.wsgi'。

追踪信息(最近的调用在最前面):

文件 "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/core/handlers/wsgi.py", 第187行,在call

self.load_middleware()

文件 "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/core/handlers/base.py", 第45行,在load_middleware中

mw_class = import_by_path(middleware_path)

文件 "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/utils/module_loading.py", 第31行,在import_by_path中

error_prefix, module_path, class_name))

配置不当:模块 "django.contrib.auth.middleware" 没有定义 "SessionAuthenticationMiddleware" 属性/类

有什么想法吗?

暂无标签

1 个回答

1

SessionAuthenticationMiddleware是Django 1.7版本中新加入的功能。你可能在你的虚拟环境中安装的是一个旧版本的Django。

撰写回答