Search code examples
ruby-on-railsrubydjangodjango-viewsrabl

Django JSON Builder like Rails JBuilder or RABL?


Anybody knows if there is any package related to templating json like Rails JBuilder or RABL gems ?

I have this code and want to separate out json rendering code and business logic code.

from django.http import HttpResponse
import json

# Create your views here.
def index(request):
    # Business logic
    # hidden ----------

    # rendering logic
    data = {'foo': 'bar'}
    another = {'something': 'hello'}

    return HttpResponse(json.dumps({'data':data,'another':another}), content_type='application/json')

Solution

  • Tastypie!

    Tastypie is a webservice API framework for Django. It provides a convenient, yet powerful and highly customizable, abstraction for creating REST-style interfaces.

    django rest framework

    Django REST framework is a powerful and flexible toolkit that makes it easy to build Web APIs.