On Jul 4, 9:51 pm, candlerb <b.cand...@pobox.com> wrote:
> OK, that's what wasn't clear to me in the documentation. For some
> reason, I can refer to 'bar' by itself when using runserver, but with
> wsgi I need to add /path/to and /path/to/foo to sys.path (or else
> refer to 'foo.bar' everywhere).

This has to do with 1/ how Python looks for modules (sys.patth), 2/
the fact that your manage.py from the root of your project (and not
from the parent directory) and 3/ some weird things happening with
manage.py and not when running behing apache or another web server.

wrt/ point #1 and #2: Python looks for modules / packages in the path
listed in sys.path, which always start with the current working
directory, so when you're running manage.py from within directory
"foo", foo is first on your sys.path, and you can directly import
'bar'. When running mod_wsgi, if you only adds "/path/to" in your
sys.path, Python will be able to find package "foo" (yes, your Django
project IS a Python package - it has a __init__.py file), and from
this sub-modules (foo.settings) and sub-packages (foo.bar), but NOT
'bar' (there's no package named 'bar' in your sys.path at this
point).

You can either add both '/path/to' and '/path/to/foo' in your sys.path
and point os.environ['DJANGO_SETTINGS_MODULE'] to 'foo.settings' and
settings.ROOT_URLCONF to 'foo.urls',  or only add '/path/to/foo' in
your sys.path and point os.environ['DJANGO_SETTINGS_MODULE'] to
'settings' and settings.ROOT_URLCONF to 'urls' (but then any use of
'foo.whatever' will break).

As far as I'm concern I prefer the second solution - I don't want to
have to change anything in my code when I rename my project dir or
move an app to another project or whatever.

wrt/ point #3, I can only point you to Graham Dumpleton's excellent
post:
http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to