如何在金字塔notfound_view_config中返回HTTPMovedPermanently(301 status)而不是HTTPFound(302)

时间:2014-07-21 12:47:47

标签: python pyramid http-status

在参数 append_slash = True 的金字塔中使用 notfound_view_config ,重定向时获得302 http状态,但我想设置自定义http状态 - 301。

@notfound_view_config(append_slash=True, renderer="not_found.mako") def notfound(request): return {}

2 个答案:

答案 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