404 The resource could not be found

喜夏-厌秋 提交于 2019-12-11 04:54:48

问题


Getting 404 Resource not found when trying to access a single item as anonymous i.e. no authenticated. I would expect instead a 403 Forbidden since I have setting permission on the view config.

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()

My views init has the traversal set as:

self.config.add_route('book', '/book/*traverse', factory="bookstoreapp.views.bok.views.book_container_factory")

Log shows that the route was matched though then shows 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: ()

The view render fine when the user is logged in just that when not, I would like to get Forbidden view instead.


回答1:


It looks like your context is BookContainer with a view_name of 8LjkOSzGSR67i1dnGUOg-Q. This does not match your required context of BookResource with a name of '' and thus would be a 404 before permissions are checked. You probably want to drop the name predicate from your view_config because you probably do not care what the name is. Also figure out why the context is not what you expect based on what's happening in your traversal tree.



来源:https://stackoverflow.com/questions/43292574/404-the-resource-could-not-be-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!