1

OK I don't what I'm doing wrong here. I have a Linode VPS running Ubuntu. I installed Django 1.3, Apache2, and mod-WSGI. I created my (extermely simple) website, slapped in some images, have a CSS sheet, have a favicon.ico and it works beautifully with the Django test server. The site looks precisely as it should -- all the images load, the CSS is working properly, etc.

Then I tried running the site with Apache and it won't work. Here are my relevant configuration files:

Apache sites-enabled/default:

<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>

My WSGI script (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()

When I try to surf to the website, I get a 500 internal error page. The traceback is this:

    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

In the traceback, I don't know why it is claiming that there is No module named quote since that module does indeed exist, and it works fine in the Django test server.

This should be straight forward. What boggles my mind is that I have a second Linode VPS running Ubuntu with a different website that has the exact configuration files and it works perfectly.

I bet this is some simple tweak and it will all work.

Any ideas?

Thanks!

2
  • Where is the 'quote' module or package located? Have you checked the permissions to ensure that user that Apache runs as can read it? Sep 21, 2011 at 8:45
  • The "quote" module is simply an app within the django_site project.
    – Garfonzo
    Sep 21, 2011 at 14:59

2 Answers 2

0

Change path in your django.wsgi to /srv/www/django_site.

It's expecting to be able to import your modules into library code elsewhere, which it can't do without having them in the path.

3
  • Unfortunately this had the effect of causing WSGI to not know where the settings file is. As a result, the fun new error in the apache error log is Could not import settings 'django_site.settings' (Is it on sys.path?): No module named django_site.settings. pulling my hair out
    – Garfonzo
    Sep 21, 2011 at 5:37
  • Do both, then. sys.path.append('/srv/www/django_site'), sys.path.append('/srv/www'). Sep 21, 2011 at 5:54
  • That doesn't change the situation.
    – Garfonzo
    Sep 21, 2011 at 6:46
0

OK -- I figured it out. After much hair pulling and frustration, it came down to a setting in my settings.py file. My original settings.py file had the installed app section with my little app quote. It looked like this:

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

The app South is the MySQL schema migration utility and then we have my single app called quote. It was this line that was causing all the errors.

The solution: add my project name in front of my app's name. Like so:

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

Yes. That is it! Now the site works through Apache as it should. I don't understand why this wasn't causing similar errors on the Django test server. Oh well.

This screw up on my part is certainly humbling!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .