在Python CGI中返回http状态代码

时间:2009-05-07 09:33:26

标签: python http cgi

是否可以通过python cgi脚本发送200以外的状态代码(例如301重定向)

2 个答案:

答案 0 :(得分:20)

通过cgi脚本?

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

答案 1 :(得分:0)

通过wsgi应用程序?

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

    return []