[mod_python] Form action handler location

Jorey Bump list+mod_python at joreybump.com
Mon May 10 14:21:59 EST 2004


Diener, Edward wrote:
> How is the location of the form's action handler determined ? 

Let's assume the form is on http://example.com/survey/index.html.

> As a 
> relative address, is it relative to the directory of the HTML file 
> itself, 

It's probably best to think in terms of location, not file or directory.
If your form is handled by the function "results" in form.py in the same
directory, your action would be:

<form name="survey" action="form/results" method="POST">

This is relative to the directory that contains the form page, and maps to:

http://example.com/survey/form/results

> to the document root directory, 

<form name="survey" action="/survey/form/results" method="POST">

Since this is relative to the DocumentRoot, it is also sometimes
referred to as absolute (not to be confused with an absolute path).

> to the server root directory, 

Nothing is relative to the ServerRoot. That's where config files are kept.

> or 
> to the root directory ?

If you mean /, no URL will ever use that format (although your python
code might use it internally to specify absolute paths of certain files
it needs to access). In other words, this is invalid if your
DocumentRoot is /var/www:

<form name="survey" action="/var/www/survey/form/results" method="POST">

If a web server sees this request from a client, it will try to serve
/var/www/var/www/survey/form/results and fail.

Finally, remember form.py? You'd think the results page could include a
link back to the form page like this:

<a href="index.html">Return to survey.</a>

But the *location* is http://example.com/survey/form/results, so the
correct link would be:

<a href="../index.html">Return to survey.</a>

Otherwise, it will look for a function named index.html in form.py. It
all boils down to counting the forward slashes.







More information about the Mod_python mailing list