Django和WSGI以及Apache2-站点在testing服务器上是完美的,不会加载Apache

好吧,我不在这里做错了什么。 我有一个运行Ubuntu的Linode VPS。 我安装了Django 1.3,Apache2和mod-WSGI。 我创build了我的(非常简单的)网站,拍了一些图片,有一张CSS表格,有一个favicon.ico,并且与Djangotesting服务器一起工作得很漂亮。 该网站看起来应该是正确的 – 所有的图像加载,CSS工作正常,等等。

然后我尝试用Apache运行该网站,它不会工作。 这里是我的相关configuration文件:

Apache网站启用/默认:

<VirtualHost *:80> ServerAdmin ***@***.com WSGIScriptAlias / /srv/www/django_site/django.wsgi AliasMatch ^/([^/]*\.css) /srv/www/django_site/static_media/css/$1 Alias /static_media/ /srv/www/django_site/static_media/ <Directory /srv/www/django_site> Options -Indexes Order deny,allow Allow from all </Directory> ErrorLog /srv/www/logs/error.log LogLevel warn CustomLog /srv/www/logs/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> 

我的WSGI脚本(django.wsgi):

 import os import sys path = '/srv/www' if path not in sys.path: sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'django_site.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

当我尝试冲浪到网站,我得到一个500内部错误页面。 追溯是这样的:

  Traceback (most recent call last): File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 111, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/srv/www/django_site/quote/views.py", line 9, in about return render_to_response("pages/about.html", context_instance=RequestContext(request)) File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py", line 20, in render_to_response return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 181, in render_to_string t = get_template(template_name) File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 157, in get_template template, origin = find_template(template_name) File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 128, in find_template loader = find_template_loader(loader_name) File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py", line 95, in find_template_loader mod = import_module(module) File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/usr/local/lib/python2.6/dist-packages/django/template/loaders/app_directories.py", line 23, in <module> raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0])) ImproperlyConfigured: ImportError quote: No module named quote 

在回溯中,我不知道为什么声称No module named quote因为该模块确实存在,并且它在Djangotesting服务器中工作正常。

这应该是直截了当的。 我的脑海里浮现的是我有另一个运行Ubuntu的Linode VPS,它具有不同的网站,它具有完全的configuration文件,并且完美地工作

我敢打赌,这是一些简单的调整,它会一切工作。

有任何想法吗?

谢谢!

django.wsgi path更改为/srv/www/django_site

它期望能够将你的模块导入到其他地方的库代码中,而不需要将它们放在path中。

好 – 我明白了。 经过很多头发拉扯和挫折,它归结为settings.py文件中的一个设置。 我的原始settings.py文件有我的小应用程序quote已安装的应用程序部分。 它看起来像这样:

 INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'south', 'quote', ) 

应用程序South是MySQL模式迁移实用程序,然后我们有我的单一应用程序称为quote 。 正是这一行导致了所有的错误。

解决scheme:将我的项目名称添加到我的应用程序名称前面。 像这样:

 INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'south', 'django_site.quote', ) 

是。 就是这样 ! 现在该网站通过Apache工作,因为它应该。 我不明白为什么这不会在Djangotesting服务器上造成类似的错误。 好吧。

这个搞砸了我肯定是谦卑!