Returning http status codes in Python CGI

…衆ロ難τιáo~ 提交于 2019-11-27 23:39:47

问题


Is it possible to send a status code other than 200 via a python cgi script (such as 301 redirect)


回答1:


via cgi script?

print "Status:301\nLocation: http://www.google.com"



回答2:


Via wsgi application?

def simple_app(environ, start_response):
    status = '301 Moved Permanently' # HTTP Status
    headers = [('Location','http://example.com')] # HTTP Headers
    start_response(status, headers)

    return []


来源:https://stackoverflow.com/questions/833715/returning-http-status-codes-in-python-cgi

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