[mod_python] Mod-Python Help

Nicolas Lehuen nicolas at lehuen.com
Mon Sep 4 14:25:50 EDT 2006


You have to provide absolute paths when accessing local file. This is
because the cwd is always /.

I you want to built paths relative to the script you are writing, you can
use the __FILE__ meta variable :

LOCAL_FILE = os.path.join(os.path.dirname(__FILE__),'myfile.txt')


2006/9/4, Ethan Toan Ton <ethanton at ethanton.com>:
> Hi,
> I'm not sure if this is the correct forum to be asking for help with
> Mod-Python, but I figure I'd give it a shot.  I was wondering if anyone
> had experience using a Mod-Python request handler to answer a javascript
> xmlhttprequest().
> When my javascript program does a request on the xml file directly, all of
> the javascript parsing of the xml works fine.  However, when I try to call
> the request handler and get it to read the file in and return the request,
> the javascript can't parse the xml.  Here's the code:
> LOCAL_FILE = 'htdocs/ethan/info.xml';
> def get_request(req):
>         if req.method == 'GET':
>                 file = open(LOCAL_FILE, 'r')
>                 req.content_type = "application/xml"
>                 req.write(file.read())
>         return apache.OK
> The same data is sent, but I'm not sure if there is a formatting problem
> here.  I'm assuming that's the problem, but I'm at a loss as to the
> solution.  req.sendfile(LOCAL_FILE) does not work either.
> Any help would be greatly appreciated.
> Ethan
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060904/8b4b337e/attachment.html

More information about the Mod_python mailing list