Django/Apache/wsgi problems -- help!

100 views
Skip to first unread message

Stephen Waterbury

unread,
Feb 19, 2009, 12:25:49 PM2/19/09
to django...@googlegroups.com
I am a developer with a deadline -- not even a perfectionist,
I just want it to work! ;)

I am running Django 1.0.2-final on Ubuntu gutsy with Python 2.5.
I am also using
* django-registration 0.7
* django-profiles 0.2

Everything works fine with django's runserver.

In the wsgi environment, the index view for one of my project
apps works, and the 'accounts/registration' url works but
is not finding its stylesheet, so apparently the media alias
I've set is not working properly. Also the /admin/ url gives
an internal error, which in apache's errlog shows a traceback
that ends in "OperationalError: no such table: django_session".

I have used sqlite3's .schema command to look at the db, and that
table is definitely there, and as I say it works fine in the
runserver environment.

I have set up wsgi according to the instructions in
<http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango>

My wsgi app script is (s/my-app-name/FOO/):

------------------------------------------------------------
import os, sys
sys.path.append('/var/www-wsgi')
sys.path.append('/var/www-wsgi/FOO')
os.environ['DJANGO_SETTINGS_MODULE'] = 'FOO.settings'

import django.core.handlers.wsgi

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

My Apache config's wsgi section is (similarly laundered):

-------------------------------------------------------------
# django wsgi app FOO
WSGIDaemonProcess mysite.com user=skred group=www-data threads=25
WSGIProcessGroup mysite.com
Alias /media/ /var/www-wsgi/FOO/media/
<Directory /var/www-wsgi/FOO/media>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /foo /var/www-wsgi/FOO/apache/django_wsgi.py
<Directory /var/www-wsgi/FOO/apache>
Order deny,allow
Allow from all
</Directory>
---------------------------------------------------------------

In my app's settings (/var/www-wsgi/FOO/settings.py) I have:

ADMIN_MEDIA_PREFIX = '/media/'

(I also have MEDIA_ROOT set -- is it necessary to have both??)

MEDIA_ROOT = '/var/www-wsgi/FOO/media'

but I would have assumed this was ignored in the wsgi environment
because of the instruction to use an ALIAS.

Also:

TEMPLATE_DIRS = (('/var/www-wsgi/FOO/templates'),)

Any ideas? I'm tearing out hair that I can ill afford to lose!

Thanks!
Steve

Polat Tuzla

unread,
Feb 20, 2009, 11:59:16 AM2/20/09
to Django users
Also the /admin/ url gives
> an internal error, which in apache's errlog shows a traceback
> that ends in "OperationalError: no such table: django_session".

This is most probably due to the fact that you did not set your
DB_NAME variable with the full path of your .db file. And sqlite3 is
creating a new .db file as it cannot access the real one.
That is:
Instead of
DATABASE_NAME = 'dev.db'
you should set it as
DATABASE_NAME = '/path/to/db/file/mydbfile.db'

And for the vhost configuation let me write down what works for me:

ServerName www.mysite.com
ServerAlias *mysite.com
Alias /media/admin /usr/lib/python2.5/site-packages/django/contrib/
admin/media
<Location /media/admin>
Order allow,deny
Allow from all
</Location>
Alias /media /path/to/project/site_media
<Location /media>
Order allow,deny
Allow from all
</Location>

WSGIScriptAlias / /path/to/project/apache/my.wsgi

WSGIDaemonProcess mysite.com user=myuser group=www-data threads=25
WSGIProcessGroup mysite.com

And set the configuration variables accordingly as:
MEDIA_ROOT = '/path/to/project/site_media/' #this is for file
uploads
MEDIA_URL = "http://mysite.com/media/"
ADMIN_MEDIA_PREFIX = '/media/admin/'

> (I also have MEDIA_ROOT set -- is it necessary to have both??)
Yes it is. At least in this configuration I am demonstrating.

Hope this helps.
Regards,

Polat Tuzla

Stephen Waterbury

unread,
Feb 20, 2009, 1:32:33 PM2/20/09
to django...@googlegroups.com
Polat,

Thank you, thank you!! That solved all the problems I had.
I was really at a loss to know where to look -- perhaps I hadn't
found the right docs, but this was the first time I had seen the
things you suggested.

One more question: in what sense did you mean that MEDIA_ROOT
"is for file uploads"? I have not begun working on file uploads
yet, but I will need that, and I see there is documentation on it
which talks about several configurable options. Did you mean that
MEDIA_ROOT is the default location for uploaded files?

Thanks again for your help -- you saved my bacon! :)
Steve

Polat Tuzla

unread,
Feb 20, 2009, 2:37:16 PM2/20/09
to Django users
I'm glad to hear that everything is solved.

> One more question:  in what sense did you mean that MEDIA_ROOT
> "is for file uploads"?  I have not begun working on file uploads
> yet, but I will need that, and I see there is documentation on it
> which talks about several configurable options.  Did you mean that
> MEDIA_ROOT is the default location for uploaded files?

Yes. Django uses MEDIA_ROOT as the root path for the upload_to
parameter for FileField and ImageField. It defines the root of the
directory tree where the files should be stored. It is typically the
place where you will want to make publicly available through your web
server.

MEDIA_URL is used when constructing url values for such fields.

> Thanks again for your help -- you saved my bacon!  :)
> Steve

You are welcome.
Regards,

Polat Tuzla
Reply all
Reply to author
Forward
0 new messages