404 The resource could not be found

736 views Asked by At

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

There are 1 answers

0
Michael Merickel On

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.