Reputation:
This is probably really simple. But I guess I'm too new to WSGI and Django to get it on my own. I have a brand new shiny Django project on a Ubuntu virtual machine hosted in /var/www/mysite. The project was created with
django-admin startproject mysite
I'm following a WSGI tutorial to get it set up, so I created an ./apache folder, inside of which I placed this file, django.wsgi:
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = '/var/www/mysite/mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I then added this config line to the Apache configuration:
WSGIScriptAlias / /var/www/mysite/apache/django.wsgi
When I try to hit the site, nothing is returned. The connection just hangs. This is in my access.log:
192.168.2.116 - - [15/Aug/2010:14:09:02 -500] "GET / HTTP/1.1" 500 639 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
So it's hitting the site. But someone isn't doing anything. There are no errors in the errors.log.
Anyone have any ideas?
Upvotes: 4
Views: 365
Reputation: 58523
The blatant mistake in original question is that:
os.environ['DJANGO_SETTINGS_MODULE'] = '/var/www/mysite/mysite.settings'
would need to be:
sys.path.append('/var/www')
sys.path.append('/var/www/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
That is, Django settings module must be a Python package path, NOT an absolute file system path. The accepted answer doesn't even point that out and rather just gives another set of code to use with no explanation.
Further, you need to set Python module search path, ie., sys.path, so that Python can find your settings file listed in that environment variable.
Finally, if your browser was hanging you have done something else wrong as well, as what you did should have resulted in an error being returned and not the browser hanging. There would also have had to be an error in the Apache error log, so you are either looking in wrong place or don't know what to look for.
Upvotes: 2
Reputation: 12263
Aren't you missing path to your Django application? My app.wsgi
has this:
import os, sys
sys.path.append('/usr/local/src/django-1.2') # django is outside default path
sys.path.append('/usr/local/src/django-photologue-2.2') # app i'm using
sys.path.append('/var/www/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
# this is regular python import, so my settings are physically
# here: /var/www/mysite/settings.py
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Upvotes: 1