List Info

Thread: Set WOrking directory with mod_python




Set WOrking directory with mod_python
user name
2006-03-30 21:45:52
Hi.

This is probably a really trivial question.
How do I set my Django app's current working directory when
running
under mod_python?

I have a view which loads local files and includes their
content in a
directory. When running under the development server, this
works fine.
Running under mod_python, I get "[Errno 2] No such
file or directory: "
-- I assume that the project  has a different working
directory when
running under mod_python.

I'm doing this in my view:

    t = loader.get_template('showpage')
    f = file('pages/%s' % path,"r")
    body = f.read()
    f.close()

I set the following options in my httpd conf:

<Location "/world">
    SetHandler mod_python
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mymodule.settings_prod
    PythonDebug On
        PythonAutoReload Off
    PythonPath "sys.path+['/srv/mymodule']"
</Location>

where mymodule is my project directory -- the directory 
'pages', from
which I'm reading the files is beneath this directory and
is readable
by the Apache user.

Is there a setting I'm missing?

Thanks for your help,

Daniel


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Set WOrking directory with mod_python
user name
2006-03-30 21:58:25
On Mar 30, 2006, at 3:45 PM, daniel.tietzegmail.com
wrote:
> This is probably a really trivial question.
> How do I set my Django app's current working directory
when running
> under mod_python?

The "correct" answer is that you shouldn't be
relying on the working  
directory in a web app; use absolute paths -- or paths
relative to  
__file__ -- instead.

However, if you're convinced this is something you need to
do, use  
os.chdir().

Jacob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Set WOrking directory with mod_python
user name
2006-03-31 09:26:53
You're right, of course.

I defined a setting in settings.py which I now use to put
together an
absolute path name. That way, I only need to change this one
central
place when redeploying to a different location (which was
what I was
thinking about when going for the relative filename stuff).

Thanks.
Daniel.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )