4

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?

2
  • Why is it named wsdl? Shouldn't it be .wsgi? Not that it probably matters.. Commented Aug 15, 2010 at 19:26
  • Sorry, it was a typo on the post. Corrected to wsgi (which it is in the file) Commented Aug 15, 2010 at 19:42

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

When I moved the wsgi file into the project root and added the path, it all worked.
Having the WSGI file in the project root is a bad idea as it implies that you would technically need to allow Apache to be able to serve up any files to a remote user from your project directory, including your settings file including database passwords. Now, you may not have any URLs mapped in Apache which mean files in project directory can actually be downloaded as static files, but you still have removed one underlying level of security. So, go back to using 'apache' subdirectory and only have 'Allow from all' for that 'apache' subdirectory containing the WSGI script file.
For further information about 'apache' subdirectory, see 'code.google.com/p/modwsgi/wiki/IntegrationWithDjango'.
1

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

1 Comment

Well, it looked like you have your app.wsgi file inside the project folder and not in a apache subfolder, so I moved mine there and changed the apache config accordingly. Ha. I got it! Thanks much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.