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 수정되지 않음 작업을 수행합니다. –