Ash
Ash

Reputation:

Returning http status codes in Python CGI

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

Upvotes: 17

Views: 9153

Answers (2)

Jiri
Jiri

Reputation: 16625

via cgi script?

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

Upvotes: 24

S.Lott
S.Lott

Reputation: 391862

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 []

Upvotes: 0

Related Questions