[mod_python] The DOs and DONTs of mod_python: one problem found

Nic Ferrier nferrier at tapsellferrier.co.uk
Tue Oct 18 21:06:50 EDT 2005


"Graham Dumpleton" <grahamd at dscpl.com.au> writes:

> Also be aware that the current working directory of Apache is not
> guaranteed. Thus, when a handler is executed, the current working
> directory WILL NOT be that of where the handler code resides. It
> is therefore very important to use absolute pathnames to resources
> you need to access. If such resource files are located in proximity
> to the handler code file, best to use something like:
>
>   import os
>   __here__ = os.path.dirname(__file__)

Isn't a better approach to abstract out the fixed file refs and pass
in docroot as a reference?

  def handler(http):
     docroot = http.document_root()
     do_some_call(docroot)
     .
     .
     .

Then you can set docroot in the apache config, eg:

  <VirtualHost *>
        ServerName rssagg.tapsellferrier.co.uk
        DocumentRoot /home/nferrier/projects/rssagg
        CustomLog /var/log/apache2/access.log tf_combined

        PythonPath "sys.path+['/home/nferrier/projects/rssagg']"
        PythonDebug On
        PythonEnablePdb Off

        .
        .
        .

  </VirtualHost>


Anyway, that's what I do.


Nic


More information about the Mod_python mailing list