7

When I'm executing

django-admin.py startproject site

it works.
But if I'm only copying site folder it doesn't work.
Why?

<VirtualHost *:80>
ServerName django.stanislavfeldman.com

# Django settings
WSGIScriptAlias / /var/www/django/wsgi_handler.py
WSGIDaemonProcess django.stanislavfeldman.com maximum-requests=200 stack-size=524288

ErrorLog /var/www/django/error.log
LogLevel warn
</VirtualHost>

wsgi_handler.py:

import os, sys

sys.path.append('/var/www/django')

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

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()
Stan
  • 4,169
  • 2
  • 31
  • 39

5 Answers5

6

If you have something like this in apache configs:

WSGIScriptAlias /path /base/path/devel/your_project.wsgi

And this inside your_project.wsgi:

sys.path.append('/base/path')
os.environ['DJANGO_SETTINGS_MODULE'] = 'devel.settings'

Then apache will look at /base/path/devel/settings.py. If you move or copy /base/path/devel to /base/path/production you have to edit DJANGO_SETTINGS_MODULE at your_project.wsgi pointing to 'production.settings'.

Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153
5

Ensure you have read:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

and also watch this presentation:

http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations

Your problem is going to be a sys.path or permissions issue which are both covered by the above.

That you are using 'maximum-requests=200 stack-size=524288' options to WSGIDaemonProcess directive makes me question whether you have referred to the mainstream documentation as basic instructions don't tell you to use them. Instead looks like you have used some arbitrary persons blog post for how to set it up, or relying on some folklore given to you on an IRC channel. :-)

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • Much much love for the "Here is how it f'n works. Learn that s**t and figure it out yourself!" approach. If you are stuck with such a problem you just want it to work. But in the long run it's always much better to really learn how it came to misbehave like that. We don't have enough answers like these. Thanks! – erikbstack Aug 19 '16 at 12:28
1

Check your python path to make sure that WSGI can reference it.

Andrew Sledge
  • 10,163
  • 2
  • 29
  • 30
1

I had a problem with a symlink not being followed from the site-packages dir. Double check your apache config and symlinks as well.

tee
  • 9
  • 3
0

This doesn't appear to be the problem in your case, but I ran smack into the same ImportError when I used the WSGIPythonPath directive (instead of the .wsgi file) to set up sys.path. That worked fine until I switched to running WSGI in daemon mode. Once you do that, you have to use the python-path argument to the WSGIDaemonProcess directive instead.

yukondude
  • 24,013
  • 13
  • 49
  • 58