未找到视图不适用于使用遍历的金字塔
Not found view doesn't work on Pyramid using traversal
我正在使用 Pyramid (1.5.7) + traversal 并遵循 documentation 我已经尝试了所有使“未找到异常视图”工作的可能方法。
from pyramid.view import notfound_view_config,forbidden_view_config, view_config
@notfound_view_config(renderer="error/not_found.jinja2")
def not_found_view(request):
request.response.status = 404
return {}
@forbidden_view_config(renderer="error/forbidden.jinja2")
def forbidden_view(request):
return {}
使用上下文:
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPForbidden, HTTPUnauthorized
@view_config(context=HTTPNotFound, renderer="error/not_found.jinja2")
def not_found_view(request):
request.response.status = 404
return {}
@view_config(context=HTTPForbidden, renderer="error/forbidden.jinja2")
def forbidden_view(request):
return {}
我正在使用 Scan 模式,但我也尝试过向配置添加自定义函数:
def main(globals, **settings):
config = Configurator()
config.add_notfound_view(notfound)
也不走运,总是遇到以下未处理的异常:
raise HTTPNotFound(msg)
pyramid.httpexceptions.HTTPNotFound: /example-url
哎哟...我的坏蛋!我正在使用一个阻止金字塔加载异常的补间:
def predispatch_factory(handler, registry):
# one-time configuration code goes here
def predispatch(request):
# code to be executed for each request before
# the actual application code goes here
response = handler(request)
# code to be executed for each request after
# the actual application code goes here
return response
return predispatch
我仍然不知道为什么,但是删除这个补间后一切似乎都按预期工作。
我正在使用 Pyramid (1.5.7) + traversal 并遵循 documentation 我已经尝试了所有使“未找到异常视图”工作的可能方法。
from pyramid.view import notfound_view_config,forbidden_view_config, view_config
@notfound_view_config(renderer="error/not_found.jinja2")
def not_found_view(request):
request.response.status = 404
return {}
@forbidden_view_config(renderer="error/forbidden.jinja2")
def forbidden_view(request):
return {}
使用上下文:
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPForbidden, HTTPUnauthorized
@view_config(context=HTTPNotFound, renderer="error/not_found.jinja2")
def not_found_view(request):
request.response.status = 404
return {}
@view_config(context=HTTPForbidden, renderer="error/forbidden.jinja2")
def forbidden_view(request):
return {}
我正在使用 Scan 模式,但我也尝试过向配置添加自定义函数:
def main(globals, **settings):
config = Configurator()
config.add_notfound_view(notfound)
也不走运,总是遇到以下未处理的异常:
raise HTTPNotFound(msg)
pyramid.httpexceptions.HTTPNotFound: /example-url
哎哟...我的坏蛋!我正在使用一个阻止金字塔加载异常的补间:
def predispatch_factory(handler, registry):
# one-time configuration code goes here
def predispatch(request):
# code to be executed for each request before
# the actual application code goes here
response = handler(request)
# code to be executed for each request after
# the actual application code goes here
return response
return predispatch
我仍然不知道为什么,但是删除这个补间后一切似乎都按预期工作。