# -*- coding: utf-8 -*-
from pyramid.view import view_config
def json_api(**params):
u"""View decorator for JSON API"""
settings = dict(renderer='json', xhr=True, _depth=1)
settings.update(params)
def wrapped(func):
return view_config(**settings)(func)
return wrapped
You can use it like this.
@json_api(route_name="api_user_detail")
def user_detail(request):
return {"id": 1, "name": "junya"}
Note that you need to increment the _depth parameter by the number of nests in the decorator.
Recommended Posts