Returning http status codes in Python CGI

2019-01-25 05:25发布

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

标签: python http cgi
2条回答
做个烂人
2楼-- · 2019-01-25 06:00

via cgi script?

print "Status:301\nLocation: http://www.google.com"
查看更多
【Aperson】
3楼-- · 2019-01-25 06:00

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 []
查看更多
登录 后发表回答