Connecting Tech Pros Worldwide Forums | Help | Site Map

redirecting to a content page

Shreyas
Guest
 
Posts: n/a
#1: Feb 21 '06
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. 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.

Instead, I am having to write intermediate steps like this into
processing.py:

Return to the <a href=contentPage.py?submit=true>page</a> you came
from.

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

Thanks,

Shreyas

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


bruno at modulix
Guest
 
Posts: n/a
#2: Feb 22 '06

re: redirecting to a content page


Shreyas wrote:[color=blue]
> 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.[/color]

And this is a GoodThing(tm). A successful post should always be followed
by a redirect.
[color=blue]
> 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.[/color]

import cgi

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

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

Nope, having a separate script doing the form processing, then
redirecting is the right thing to do.
[color=blue]
>
> - I did try searching for this in the archive but am not even entirely
> sure what it is called...[/color]

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@xiludom.gro'.split('@')])"
Steve Holden
Guest
 
Posts: n/a
#3: Feb 22 '06

re: redirecting to a content page


bruno at modulix wrote:[color=blue]
> Shreyas wrote:[/color]
[...][color=blue][color=green]
>>The thing is, processing.py doesn't have any content that I want to
>>display to the user.[/color]
>
>
> And this is a GoodThing(tm). A successful post should always be followed
> by a redirect.
>[/color]
Really? Why's that?
[color=blue]
>[...][/color]

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Shreyas
Guest
 
Posts: n/a
#4: Feb 22 '06

re: redirecting to a content page


Thanks much, Location: took care of what I needed. I'll look to the
http protocols for the future.

Shreyas

Closed Thread