0

我正在使用 wsgi 在 apache2 中运行应用程序,但出现此错误:

> mod_wsgi (pid=26904): Exception occurred processing WSGI script
> '/var/www/multidb/multidb/wsgi.py'. Traceback (most recent call last):
> File "/usr/lib/python3/dist-packages/django/core/handlers/wsgi.py",
> line 170, in call self.load_middleware() File
> "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line
> 50, in load_middleware mw_class = import_string(middleware_path) File
> "/usr/lib/python3/dist-packages/django/utils/module_loading.py", line
> 26, in import_string module = import_module(module_path) File
> "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
> return _bootstrap._gcd_import(name[level:], package, level) File "",
> line 986, in _gcd_import File "", line 969, in _find_and_load File "",
> line 944, in _find_and_load_unlocked File "", line 222, in
> _call_with_frames_removed File "", line 986, in _gcd_import File "", line 969, in _find_and_load File "", line 956, in
> _find_and_load_unlocked ImportError: No module named 'subdomains'

这是我的包含子域的中间件:

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'subdomains.middleware.SubdomainURLRoutingMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

我已经使用 pip 安装了 django-subdomains,它在站点包中可用。

4

1 回答 1

0

在虚拟环境中工作时,需要设置PYTHONPATH变量。

您可以执行以下操作:

  • 在项目目录之外创建一个 init.sh 文件
  • 使文件可执行 ( <chmod 777 filename>)
  • 在 init.sh 中:

ABS_WORK_DIR = '密码 -P'

导出 PYTHONPATH = ${ABS_WORK_DIR}/apps:${ABS_WORK_DIR}/lib:${ABS_WORK_DIR}/local

于 2016-07-10T09:26:26.660 回答