web.pyが301や他のリダイレクトタイプに対してこれを行う方法は、web.HTTPError
(これはweb.ctx.status
をサブクラス化する)です。たとえば、次のように
class MultipleChoices(web.HTTPError):
def __init__(self, choices):
status = '300 Multiple Choices'
headers = {'Content-Type': 'text/html'}
data = '<h1>Multiple Choices</h1>\n<ul>\n'
data += ''.join('<li><a href="{0}">{0}</a></li>\n'.format(c)
for c in choices)
data += '</ul>'
web.HTTPError.__init__(self, status, headers, data)
次に出力し、このステータスコードあなた、あなたのハンドラでraise MultipleChoices
:
class MyHandler:
def GET(self):
raise MultipleChoices(['http://example.com/', 'http://www.google.com/'])
それはもちろん、あなたの特定のunAPIアプリケーションのチューニングが必要になります。
the source for web.HTTPError
in webapi.pyも参照してください。
このメソッドは、一部のイメージをプログラムで提供する場合には304 Not Modifiedのジョブも行います –