1

我正在尝试将我的应用程序从 django 1.2 升级到 1.4,我已经使用内置的网络服务器成功测试了它。

但是,我在将其部署为带有 Apache(在 Ubuntu 上)的 VirtualHost 时遇到了问题。

我的sites-available/default包含:

<VirtualHost *:80>
    ServerName myapplication

    WSGIScriptAlias / /usr/share/myapplication/wsgi.py
    WSGIDaemonProcess myapplication python-path=/usr/share/myapplication:/usr/lib/python2.6/dist-packages

    <Directory /usr/share/myapplication>
    <Files wsgi.py>
      Order deny,allow
      Allow from all
    </Files>
    </Directory>

</VirtualHost>

该文件/usr/share/myapplication/wsgi.py包含标准:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapplication.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Apache 可以正常启动,但是当我转到http://myapplication“500:内部服务器错误”时,Apache 日志显示:

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

我正确使用 WSGIDaemonProcess 吗?django 文档不清楚。

谢谢

4

2 回答 2

3

使用以下方法解决了这个问题,来自http://rc98.net/django_wsgi

网站可用/默认:

<VirtualHost *:80>
    ServerName myapplication

    WSGIDaemonProcess myapplication
    WSGIProcessGroup myapplication

    WSGIScriptAlias / /usr/share/myapplication/wsgi.py
    <Directory /usr/share/myapplication>
    <Files wsgi.py>
      Order deny,allow
      Allow from all
    </Files>
    </Directory>

</VirtualHost>

和wsgi.py:

import os,sys

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
    sys.path.append(path)

path = '/usr/share/myapplication'
if path not in sys.path:
    sys.path.append(path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapplication.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
于 2012-05-25T13:01:21.530 回答
1

Could you print your path at runtime:

#init.py

    import sys
    print sys.path
  1. have you got an init file in the project base dir?
  2. does it work if you import settings instead of myapp.settings?
于 2012-05-25T10:22:30.983 回答