我正在使用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,它可以在site-packages中使用。
答案 0 :(得分:0)
在虚拟环境中工作时,您需要设置PYTHONPATH
变量。
您可以执行以下操作:
<chmod 777 filename>
)ABS_WORK_DIR =&#39; pwd -P&#39;
export PYTHONPATH = $ {ABS_WORK_DIR} / apps:$ {ABS_WORK_DIR} / lib:$ {ABS_WORK_DIR} / local