Problem setting up django on Apache

This is probably very simple. But I think I'm too new to WSGI and Django to get it on my own. I have a new brilliant Django project on an Ubuntu virtual machine hosted in / var / www / mysite. The project was created using

django-admin startproject mysite 

I am following the WSGI tutorial to configure it, so I created a folder. / apache inside 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() 

Then I added this configuration line to the Apache configuration:

 WSGIScriptAlias / /var/www/mysite/apache/django.wsgi 

When I try to get to the site, nothing returns. The connection just freezes. 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 he gets to the site. But someone does nothing. There are no errors in error.log.

Does anyone have any ideas?

+4
source share
2 answers

The glaring mistake in the original question is this:

 os.environ['DJANGO_SETTINGS_MODULE'] = '/var/www/mysite/mysite.settings' 

it should be:

 sys.path.append('/var/www') sys.path.append('/var/www/mysite') os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' 

That is, the Django settings module should be the path of the Python package, and not the absolute path to the file system. The accepted answer does not even indicate this, but simply gives a different set of code for use without explanation.

In addition, you need to set the Python module search path, i.e. sys.path, so that Python can find your settings file specified in this environment variable.

Finally, if your browser hung, you did something else as you should have led to the error return, and not to the browser freezing. There should also have been an error in the Apache error log, so you either look in the wrong place or you don’t know what to look for.

+2
source

Are you missing the path to your Django app? My app.wsgi has the following:

 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
source

All Articles