skroth
skroth

Reputation: 381

Can't get mod_wsgi and Apache with Django to work

This is the error I get in my Apache error log:

[Sun Aug 22 16:52:06 2010] [error] [client 127.0.0.1] ImportError: No module named settings

This is my .wsgi file, per this blog post:

import sys

sys.path.insert(0, '/home/wot/django-projects/aedo')
import settings
import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')
command.validate()
import django.conf
import django.utils

django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I've double and triple checked the path name, and that is indeed the path to my project file. I've been trying to get this to work for hours, and have done much googling. I'm asking here as my last resort. I'm desperate!

EDIT: I'm aware that there are similar questions here on SA, and I've read through most all of them, to no avail

Upvotes: 6

Views: 2427

Answers (4)

Kevin Parker
Kevin Parker

Reputation: 17206

For me I had weird import issues, Python claimed Django could not import Site... Because my install went from a purely "python runserver..." to a WSGI environment, the permissions was actually a problem.

Surprised as I didn't even change the permission on the django.contrib.site package, just all of the project's files to 755.

Upvotes: 0

user201788
user201788

Reputation:

try changing

os.environ['DJANGO_SETTINGS_MODULE'] = 'aedo.settings'

to

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

Actually I was getting this error too and I did the above. I also changed

ROOT_URLCONF =  'appname.urls' 

to

ROOT_URLCONF =  'urls' 

I hope your settings.py is in the same directory as the wsgi file for this project.

Upvotes: 2

laurent
laurent

Reputation: 908

It doesn't work when you put:

import os, sys
sys.path.append('/usr/local/django')    # obs: path to django
sys.path.append('/home/wot/django-projects/aedo')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

in your django.wsgi file?

Upvotes: 2

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

What is the output from running:

ls -las /home/wot/django-projects/aedo/

Is the directory and all the files readable to user that Apache runs as? If they aren't you may get that error.

Also watch talk and look at slides mentioned at:

http://blog.dscpl.com.au/2010/06/sydney-pycon-modwsgi-talk-slides.html

as it discusses permissions issues further.

Upvotes: 2

Related Questions