[mod_python] converting site from CGI to mod_python

Graham Dumpleton graham.dumpleton at gmail.com
Sun Nov 2 21:49:15 EST 2008


2008/11/3 Adam <adam at fastmail.com.au>:
> Actually, just another thing as well, I will need to do the same thing for
> my templates directory.
>>
>> This directory has three subdirectories.
>>  -config
>>  -content
>>      -templates
>>  -scripts
>
> Is there a standard way of dealing with path names in mod_python, or is the
> way that you suggested the best method of using files which do not reside in
> the web site folders.

If you want code that you can moved around in filesystems without
having to change, then basing decisions about where files are relative
to some anchor such as __file__ is best. Alternatively, you will need
to define config variables with absolute paths and create paths
relative to that.

The important thing you need to realise is that you cannot depend on
the current working directory being a specific value. You cannot even
set the current working directory and expect it to stay that. This is
because Apache can be running multiple applications, not just
mod_python, but PHP etc etc. If any application changes working
directory then your view of the world will be changed.

Thus, you need to ensure you use absolute path names, constructed
relative to __file__, or relative to a configuration setting which
records an absolute base setting.

Graham


More information about the Mod_python mailing list