Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyramid: Views registered with `view_config` not being associated with routes

Tags:

python

pyramid

I'm declaring a route like this:

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

And in my_package.views I have the view:

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

But route isn't being associated with the view.

Specifically, checking routes in the debug toolbar shows that no view callable is associated with the hello route, and visiting /hello returns a 404.

Changing the route definition to something like config.add_route("hello", "/hello", views.hello) works correctly.

What am I doing wrong?

like image 402
David Wolever Avatar asked May 19 '12 19:05

David Wolever


1 Answers

You are naming the view, not the route in your @view_config decorator. You want:

@view_config(route_name='hello')
def hello(request):
    return Response("Hello, world!")
like image 84
lambacck Avatar answered Oct 05 '22 23:10

lambacck