I'm trying to make sure that all paths in my Python code are relative
paths. But I think I need to know where I can put the cwd change so that
it runs when Django first comes up.
I'm on Apache and mod_python on Windows.
Thanks,
Michael
No, you don't. What you want to do is set the Python path variable in
your environment. Have a look at Django's documentation on mod_python
setup to see how to set that environment variable. That's the standard
way to do this.
Malcolm
--
Save the whales. Collect the whole set.
http://www.pointy-stick.com/blog/
I think we're talking about two different things. I have the PythonPath
variable set in my httpd.conf file. No problem with imports.
I wasn't speaking of imports.
But I have lots of "data" files that live in and around my Django code
and I have to access with them with stuff like:
f = open("somedir/myfile.dat", 'r')
So how do I make those lines look like that instead of having a bunch of
absolute paths stuck in there or lots of messy stuff with
os.path.join(os.path.dirname(__file__)...) in it?
Thanks,
Michael
[...]
> But I have lots of "data" files that live in and around my Django
> code and I have to access with them with stuff like:
>
> f = open("somedir/myfile.dat", 'r')
>
> So how do I make those lines look like that instead of having a bunch of
> absolute paths stuck in there or lots of messy stuff with
> os.path.join(os.path.dirname(__file__)...) in it?
Don't use specific paths throughout your code. Set variables in
settings.py and scatter those around.
To avoid the proliferation of os.path.* everywhere, I use something
like this in my settings files:
import os
HOME = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIRS = (
HOME + "/templates",
)
UPLOADS = HOME + "/files"
and so on.
-Drew
Ok. Thanks. The idea of putting it in settings.py is probably the path
of least litter.
Michael
Me like. Thanks.
Michael
Just to close the loop on this, Graham's explanation makes perfect sense.
But why are these instructions even included in the book and in the
documentation?
------
http://www.djangoproject.com/documentation/fastcgi/
http://www.djangobook.com/en/1.0/chapter20/
'Running Django on a shared-hosting provider with Apache'
"Create a file mysite.fcgi ..."
# Switch to the directory of your project. (Optional.)
# os.chdir("/home/user/myproject")
------
Shouldn't this be removed (or at least padded with some warnings) since
it is arguably encouraging a (new?) user to do something that is poor
practice or even dangerous.
Thanks,
Michael