第一次让Django / WSGI运行,遇到一些问题

时间:2011-06-20 02:01:00

标签: python django configuration apache2 wsgi

我安装了Python,我可以在命令行运行脚本就好了。但我想用它构建网页,并使用Django框架。

我已经阅读了很多关于如何设置和运行django的文档。 大多数工作都是使用apt-get install完成的,它安装了所需的一切,但是我遇到了麻烦的vhost配置。目前我收到500 Server错误,在错误日志中我看到导入错误。

这是完整的vhost文件:

    <VirtualHost *:80>
        ServerAdmin richtestani@mac.com
        ServerName friendflix.me
                ServerAlias www.friendflix.me
        DocumentRoot "/srv/www/friendflix.me/public_html/"
        ErrorLog /srv/www/friendflix.me/logs/error.log
            CustomLog /srv/www/friendflix.me/logs/access.log combined

            WSGIScriptAlias / /srv/www/friendflix.me/application/django.wsgi
      <Directory /srv/www/friendflix.me/application>
 Order allow,deny
Allow from all
  </Directory>

    <Location "/application">
SetHandler python-program
  PythonOption django.root /application
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE settings
PythonPath "['/srv/www/friendflix.me/application', '/srv/www/friendflix.me/publ$
PythonDebug On
</Location>

Alias /static /srv/www/friendflix.me/public_html/static
</VirtualHost>

错误的尾巴。日志

[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]     self.load_middleware() 
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]   File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]   File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 276, in __getattr__
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]     self._setup()
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]   File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 42, in _setup
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]     self._wrapped = Settings(settings_module)
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]   File "/usr/local/lib/python2.6/dist-packages/django/conf/__init__.py", line 89, in __init__
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Sun Jun 19 21:28:07 2011] [error] [client 74.89.144.194] ImportError: Could not import settings 'settings' (Is it on sys.path?): No module named settings

应用程序的目录结构(或至少)

html root

/srv/www/friendflix.me/public_html

应用程序根目录

/srv/www/friendflix.me/application

Django / wsgi应用程序配置

/srv/www/friendflix.me/application/django.wsgi

Django.wsgi脚本

import os
import sys

sys.path.append('/srv/www/friendflix.me/application')

os.environ['PYTHON_EGG_CACHE'] = '/srv/www/friendflix.me/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

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

任何帮助解决这个问题都会很棒 - 谢谢! 富

1 个答案:

答案 0 :(得分:0)

来自文档:

  

DJANGO_SETTINGS_MODULE 的值应采用Python路径语法,例如:的 mysite.settings 的    designating-the-settings
   modpython basic-configuration

因此,如果您的项目(网站)名称为application

SetEnv DJANGO_SETTINGS_MODULE application.settings