在参数 append_slash = True 的金字塔中使用 notfound_view_config ,重定向时获得302 http状态,但我想设置自定义http状态 - 301。
@notfound_view_config(append_slash=True, renderer="not_found.mako")
def notfound(request):
return {}
答案 0 :(得分:2)
HTTP {{{{{{{{{{{
AppendSlashNotFoundViewFactory
(未经测试,视为伪代码)
答案 1 :(得分:1)
我的弃用类解决方案:
class append_slash_notfound_factory(AppendSlashNotFoundViewFactory):
def __call__(self, context, request):
result = super(append_slash_notfound_factory, self).__call__(context, request)
if isinstance(result, HTTPFound):
return HTTPMovedPermanently(result.location)
return result