I've inherited a project and I'm trying to make it as clean as possible. As it is now, each view just has if/else blocks that handle the different HTTP request methods (GET, POST, DELETE, etc). I would like to have a view method that can handle not only each route, but each route + request method combination.
I'm trying this
@view_config(route_name='foo', request_method='GET', renderer='json')
def foo(request):
return Response(json.dumps({'route' : 'foo', 'method' : 'GET'}))
@view_config(route_name='foo', request_method='POST', renderer='json')
def foo(request):
return Response(json.dumpds({'route' : 'foo', 'method' : 'POST'}))
but it's not working. Can anyone help?