Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > CGI Redirect to another page

Reply
Thread Tools

CGI Redirect to another page

 
 
Andrew Chalk
Guest
Posts: n/a
 
      09-24-2003
In a Python script running under CGI, can I programatically redirect the
program to another page. Assume that I have a static HTML page that I want
displayed (e.g. index.htm). Other than 'print ...' is there any way to
redirect to this URL (for example, like Response.Redirect() in ASP)?

Many thanks.


 
Reply With Quote
 
 
 
 
Andrew Dalke
Guest
Posts: n/a
 
      09-24-2003
Andrew Chalk:
> Assume that I have a static HTML page that I want
> displayed (e.g. index.htm). Other than 'print ...' is there any way to
> redirect to this URL (for example, like Response.Redirect() in ASP)?


The Response.Redirect likely works by putting something in
the header. The HTML page you have doesn't have access to
the header. However, you can use the meta tag to tell the
browser to look elsewhere. But that won't work for tools which
don't parse the HTML.

It's an easy web search (once you know the right keywords -
"header redirect meta" and I found
http://vancouver-webpages.com/META/FAQ.html#redirect
"How can I redirect the user to another page ?"
with three different answers

Andrew
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
 
 
 
Tim Howarth
Guest
Posts: n/a
 
      09-24-2003
In message <NW7cb.525$(E-Mail Removed) m>
"Andrew Chalk" <(E-Mail Removed)> wrote:

> In a Python script running under CGI, can I programatically redirect the
> program to another page.


Do you mean redirect the client browser ?

> Assume that I have a static HTML page that I want displayed (e.g.
> index.htm). Other than 'print ...' is there any way to redirect to this
> URL (for example, like Response.Redirect() in ASP)?


Assuming you mean not to print the whole page, when you say "Other than
'print ...'" then;

print "Location: http:abcxyz.index.html"

AFAIUI it simply sends a redirect header.

--
___
|im ---- ARM Powered ----
 
Reply With Quote
 
Tim Howarth
Guest
Posts: n/a
 
      09-24-2003
In message <(E-Mail Removed)>
Tim Howarth <(E-Mail Removed)> wrote:

> In message <NW7cb.525$(E-Mail Removed) m>
> "Andrew Chalk" <(E-Mail Removed)> wrote:
>
> > In a Python script running under CGI, can I programatically redirect the
> > program to another page.

>
> print "Location: http:abcxyz.index.html"


Or even a properly formed URL !

--
___
|im ---- ARM Powered ----
 
Reply With Quote
 
Andrew Chalk
Guest
Posts: n/a
 
      09-24-2003
Thanks, good web search! I couldn't get "Location:URL" to work but META did.

Regards.

"Andrew Dalke" <(E-Mail Removed)> wrote in message
news:4n9cb.1447$(E-Mail Removed) nk.net...
> Andrew Chalk:
> > Assume that I have a static HTML page that I want
> > displayed (e.g. index.htm). Other than 'print ...' is there any way to
> > redirect to this URL (for example, like Response.Redirect() in ASP)?

>
> The Response.Redirect likely works by putting something in
> the header. The HTML page you have doesn't have access to
> the header. However, you can use the meta tag to tell the
> browser to look elsewhere. But that won't work for tools which
> don't parse the HTML.
>
> It's an easy web search (once you know the right keywords -
> "header redirect meta" and I found
> http://vancouver-webpages.com/META/FAQ.html#redirect
> "How can I redirect the user to another page ?"
> with three different answers
>
> Andrew
> (E-Mail Removed)
>
>
>



 
Reply With Quote
 
Andrew Clover
Guest
Posts: n/a
 
      09-24-2003
Tim Howarth <(E-Mail Removed)> wrote:

> print "Location: http://abcxyz/index.html"


> AFAIUI it simply sends a redirect header.


Yep; however, if you include a relative URI with no hashpart:

print 'Location: /index.html'
print

Then the server should send that page to the browser directly, without
sending a redirect back to the browser. This may be preferable in
some cases.

(The second print is needed to end the CGI response headers.)

Full spec here:

http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

(Using JavaScript or meta-refresh to do redirects is almost always a
really terrible idea.)

--
Andrew Clover
(E-Mail Removed)
http://www.doxdesk.com/
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-24-2003
On Wed, 24 Sep 2003, Andrew Chalk wrote:

> In a Python script running under CGI, can I programatically redirect the
> program to another page. Assume that I have a static HTML page that I
> want displayed (e.g. index.htm). Other than 'print ...' is there any way
> to redirect to this URL (for example, like Response.Redirect() in ASP)?


you have two options:

- write a Location header; the web server will notice it and spit out the
file you specify

- write Status and Location headers, giving status 302 (or 303); the web
server will notice the Status header and give the client the appropriate
status code; the client will then follow the redirect you give it in the
Location header

see:

http://hoohoo.ncsa.uiuc.edu/cgi/out.html
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

tom

--
One chants out between two worlds Fire - Walk With Me.

 
Reply With Quote
 
John J. Lee
Guest
Posts: n/a
 
      09-24-2003
(E-Mail Removed) (Andrew Clover) writes:
[...]>
> (Using JavaScript or meta-refresh to do redirects is almost always a
> really terrible idea.)


I know I don't like them "on principle", but what practical problems
do they cause? Do proper HTTP redirects avoid the "back button trap",
maybe? I've never noticed...


John
 
Reply With Quote
 
Andrew Chalk
Guest
Posts: n/a
 
      09-24-2003
What is wrong with meta-refresh?

"Andrew Clover" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Tim Howarth <(E-Mail Removed)> wrote:
>
> > print "Location: http://abcxyz/index.html"

>
> > AFAIUI it simply sends a redirect header.

>
> Yep; however, if you include a relative URI with no hashpart:
>
> print 'Location: /index.html'
> print
>
> Then the server should send that page to the browser directly, without
> sending a redirect back to the browser. This may be preferable in
> some cases.
>
> (The second print is needed to end the CGI response headers.)
>
> Full spec here:
>
> http://hoohoo.ncsa.uiuc.edu/cgi/interface.html
>
> (Using JavaScript or meta-refresh to do redirects is almost always a
> really terrible idea.)
>
> --
> Andrew Clover
> (E-Mail Removed)
> http://www.doxdesk.com/



 
Reply With Quote
 
Erik Max Francis
Guest
Posts: n/a
 
      09-24-2003
Andrew Chalk wrote:

> What is wrong with meta-refresh?


The use of the Location header is much more direct.

--
Erik Max Francis && (E-Mail Removed) && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ An undevout astronomer is mad.
\__/ Edward Young
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect to another web page using CGI ? vivekian Perl Misc 1 03-08-2007 05:52 AM
Calling another cgi program using CGI.pm dmedhora@gmail.com Perl Misc 12 08-28-2006 01:00 AM
Python CGI - Accepting Input, Invoking Another Process, Ending CGI LarsenMTL Python 4 11-04-2004 05:59 PM
Basic Q - Response.Redirect, all redirect to first Response.Redirect statement Sal ASP .Net Web Controls 1 05-15-2004 03:46 PM
How to make a page stay open only for few soconds, then redirect automaticaly to another page NWx ASP .Net 3 02-16-2004 05:21 PM



Advertisments