无法在Apache Server上运行我的Django站点(版本1.6)

时间:2014-02-15 06:44:42

标签: django apache

我正在运行一个先前在django 1.4上运行的网站,但现在我将它移到了django 1.6上。

我可以使用python manage.py shell在两个版本上运行我的网站。

当我在Apache网站启用时保持django 1.4虚拟环境python路径时,我在Apache上运行得很好,但是当我在那里保留django 1.6虚拟环境python路径时它不起作用。

对于django 1.6,它会抛出错误:

  

NotperlyConfigured:请求设置DEBUG,但未配置设置。您必须定义环境变量DJANGO_SETTINGS_MODULE或在访问设置之前调用settings.configure()

有什么问题? django 1.6的wsgi.py文件中需要进行哪些更改?请帮忙。

我的虚拟主机文件是:

<VirtualHost *:80>
    ServerAdmin vidya.sagar0911@gmail.com
    DocumentRoot /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/
    ServerName www.vidblog.com
    <Directory /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo>
            #Order deny,allow
            #Allow from all
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    Alias /media /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/vidyamedia/
    Alias /static /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/static/
    WSGIDaemonProcess www.demo.com user=www-data group=www-data processes=8 threads=75\
    python-path=/home/vidya/workspace/djnago1.6/lib/python2.7/site-packages
    WSGIProcessGroup www.vidblog.com
    WSGIScriptAlias / /home/vidya/workspace/vidya/vidya_rose/cms/trunk/demo/demo/wsgi.py
</VirtualHost>

1 个答案:

答案 0 :(得分:4)

当您将旧项目从django-1.x(&lt; 1.6)迁移到django-1.6时需要定义 DJANGO_SETTINGS_MODULE ,然后再调用 get_wsgi_application

import os
import sys

sys.path.append(os.path.dirname(os.path.dirname(__file__)))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()