开发者

How to redirect to another page in Python in CGIAr

开发者 https://www.devze.com 2022-12-14 12:38 出处:网络
If I want to redirect the user from a cgi script to a HTML page using core libraries from the following:

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.开发者_如何学Go 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


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

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号