尝试以匿名方式访问单个项目(即未经过身份验证)时找不到 404 资源。我希望改为 403 Forbidden 因为我在视图配置上设置了权限。
class BookShow(FormView):
"""Show one instance of a model."""
resource_buttons = [...]
@view_config(route_name="book", context=BookResource, name="", renderer="site/workspace/book/single.html", permission="authenticated")
def book(self):
...
return locals()
我的视图 init 将遍历设置为:
self.config.add_route('book', '/book/*traverse', factory="bookstoreapp.views.bok.views.book_container_factory")
日志显示路由匹配,但随后显示 404 debug_notfound:
2017-04-08 12:36:09 mamachine pyramid_debug[685] DEBUG route matched for url http://localhost:6543/book/8LjkOSzGSR67i1dnGUOg-Q; route_name: 'book', path_info: '/book/8LjkOSzGSR67i1dnGUOg-Q', pattern: '/book/*traverse', matchdict: {'traverse': ('8LjkOSzGSR67i1dnGUOg-Q',)}, predicates: ''
2017-04-08 12:36:09 mamachine pyramid_debug[685] DEBUG debug_notfound of url http://localhost:6543/book/8LjkOSzGSR67i1dnGUOg-Q; path_info: '/book/8LjkOSzGSR67i1dnGUOg-Q', context: <bookstoreapp.views.book.views.BookContainer object at 0x7eff6d5d1fd0>, view_name: '8LjkOSzGSR67i1dnGUOg-Q', subpath: (), traversed: (), root: <bookstoreapp.views.book.views.BookContainer object at 0x7eff6d5d1fd0>, vroot: <bookstoreapp.views.book.views.BookContainer object at 0x7eff6d5d1fd0>, vroot_path: ()
当用户登录时,视图呈现良好,只是在没有登录时,我想获得 Forbidden 视图。