Pyramid: views registered with `view_config` are not associated with routes

I declare the route as follows:

from my_package import views
config.add_route("hello", "/hello")
config.scan(views)

And in my_package.viewsI have a view:

from pyramid.view import view_config
@view_config(name="hello")
def hello(request):
    return Response("Hello, world!")

But the route is not associated with the view.

In particular, checking the routes on the debug toolbar shows that the called call is not connected to the route hello, and the visit /helloreturns 404.

Changing the definition of the route to something seems to config.add_route("hello", "/hello", views.hello)work correctly.

What am I doing wrong?

+5
source share
1 answer

You name the view, not the route, in your @view_config decorator. Do you want to:

@view_config(route_name='hello')
def hello(request):
    return Response("Hello, world!")
+7
source

All Articles