404无法找到资源

时间:2017-04-08 09:54:01

标签: pyramid websauna

尝试以匿名方式访问单个项目时未找到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: ()

当用户登录时,视图呈现正常,而不是,我想获取禁止视图。

1 个答案:

答案 0 :(得分:1)

您的上下文似乎是BookContainer view_name 8LjkOSzGSR67i1dnGUOg-Q。这与BookResource name ''的{​​{1}}所需的上下文不匹配,因此在检查权限之前将为404。您可能希望从name中删除view_config谓词,因为您可能不在乎名称是什么。还要根据遍历树中发生的情况找出上下文不符合预期的原因。