How to redirect to another page in Python in CGIAr

有些话、适合烂在心里 提交于 2019-12-11 05:27:59

问题


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


回答1:


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

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



回答2:


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.



来源:https://stackoverflow.com/questions/1948756/how-to-redirect-to-another-page-in-python-in-cgiar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!