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?
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!")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With