REA_ANDREW
REA_ANDREW

Reputation: 10764

How to redirect to another page in Python in CGIAr

If I want to redirect the user from a cgi script to a HTML page using core libraries from the following:

import cgi

Please could someone point me in the right direction. Nothing more. Simply redirect from cgi script to html page. How ever you would do this Python. If you have to physically write out the HTTP Response Headers to achieve this, then I would appreciate any info on how to do this. TIA

Andrew

Upvotes: 1

Views: 5140

Answers (2)

kkk
kkk

Reputation: 1920

To redirect use Location header

print "Location:URL\r\n"  # URL is the location where you want to redirct to

One point to remember is that location header should be written before any other print statements.If other print statements are written before it then the loaction header will be printed in the screen just as normal text.

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 881715

You need to output one more header ("Status") in addition to the Location one, e.g.:

print "Status: 301 Moved",
print "Location:/wherever.com/"

Upvotes: 4

Related Questions