redirecting to a content page

bruno at modulix onurb at xiludom.gro
Wed Feb 22 03:43:14 EST 2006


Shreyas wrote:
> I am a new user writing some scripts to store data entered via a
> browser into a database.  I have several content pages, and one
> "processing" page.  A content page often has a form like this:
> 
> <form method=POST action=processing.py>
> <input type=text name=username>
> ...
> 
> And the processing page goes like this:
> 
> form = cgi.FieldStorage()
> ## do some work, put data into the db
> 
> The thing is, processing.py doesn't have any content that I want to
> display to the user.

And this is a GoodThing(tm). A successful post should always be followed
by a redirect.

>  I would ideally like processing.py to seamlessly
> send the user back to the content page that it came from, perhaps with
> some parameter tweaks.

import cgi

print "Location: %s\n\n" % url_of_the_page_you_want_to_redirect_to

(snip)

> Please let me know if there's a way to do this, or if my general
> approach (having such a processing page) is off.

Nope, having a separate script doing the form processing, then
redirecting  is the right thing to do.

> 
> - I did try searching for this in the archive but am not even entirely
> sure what it is called...

It's a redirection. If you are to work with CGI (or any other web
programming solution FWIW), you'd better know the HTTP protocol.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list