[mod_python] Trouble fetching POST arguments

Graham Dumpleton grahamd at dscpl.com.au
Thu Mar 17 00:30:33 EST 2005


Davin Boling wrote ..
> Found it, and damn was it ever an obsure one. Basicly, Apache+mod_python
> gets confused when you try to do a POST to a URI which corresponds to a
> real directory on the filesystem.
> 
> 
> I understand that's a bit hard to follow, so I'll provide the following
> example:
> 
> 1) DocumentRoot is /home/foobar/public_html/python
> 2) In this directory, you have a folder named "htdocs".
> 3) Inside this directory, you have a number of HTML templates which are
> combined to form the full document.
> 4) The handler is written so that when a client requests 
> foobar.com/htdocs, they aren't served a real file on the filesystem, but
> a dynamic document generated from the templates in the corresponding 
> filesystem directory.
> 5) THE PROBLEM: User attempts to post action="http://foobar.com/htdocs".
> 6) Unexplainable GET->POST calamity rears its ugly head.
> 7) SOLUTION: Add a trailing slash. It's the proper syntax anyway! 
> action="http://foobar.com/htdocs/"
> 8) BETTER SOLUTION: Don't be a halfass, store your templates somewhere
> on the filesystem that isn't accessible by the web. Even if the 
> templates don't contain any secure information, it's good to get in the
> practice.

FWIW, did my own test and yes you are absolutely correct about 5,6,7.

Quite interesting behaviour which I wasn't aware of before. It is worth
remembering in as much as it means you can't have a default index
page for a directory be a form which you use POST with and a URL
which maps to the directory rather than the specific index page. In
effect it is because POST data will not survive an URL redirection.

I don't believe however your suggestion in 8 makes any difference.
You would still need to add the trailing slash mentioned in 7 anyway
if you were using a URL which actually mapped to the root directory
where the PythonHandler was defined, or any subdirectory for that
matter.

Thus 8 really comes down to a matter of preferences of how to
structure your application, I don't really see it as a better solution.

Graham


More information about the Mod_python mailing list