1

我试图通过 wsgi 配置 apache 和 django。但是我遇到了有关导入设置的错误,例如:

ImportError: Could not import settings 'mymask.settings' (Is it on sys.path?): No module named mymask.settings

布局

我的网站和我的应用程序位于以下结构中:

[root@Fileserver opt]# tree django/mysite2/
django/mysite2/
|-- 1
|-- README
|-- TEMPLATES
|   |-- contact_form.html
|   |-- timedate.html
|   |-- whatmask_input.html
|   |-- whatmask_input.html.bak
|   |-- whatmask_output.html
|   `-- whois_output.html
|-- __init__.py
|-- __init__.pyc
|-- apache
|   `-- django.wsgi
|-- manage.py
|-- mymask
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- models.py
|   |-- models.pyc
|   |-- tests.py
|   |-- views.py
|   `-- views.pyc
|-- settings.py
|-- settings.pyc
|-- static
|   |-- css
|   |-- images
|   `-- js
|       `-- jquery.js
|-- timedate
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- models.py
|   |-- tests.py
|   |-- views.py
|   `-- views.pyc
|-- urls.py
`-- urls.pyc

apache/django.wsgi

import os, sys

path = '/opt/django/mysite2/mymask'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mymask.settings'

import django.core.handlers.wsgi

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

httpd.conf

# Django

Alias /media/ /opt/django/mysite2/media

<Directory /opt/django/mysite2/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /opt/django/mysite2/apache/django.wsgi

<Directory /opt/django/mysite2/apache>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /opt/django/mysite2/apache/django.wsgi

有任何想法吗 ??

4

1 回答 1

2

设置不在mymask,它在基本django/mysite目录中。因此,您应该将其添加到sys.path,并将您的设置DJANGO_SETTINGS_MODULEsettings

于 2012-05-19T09:26:53.787 回答