title: Adding root element to json response (django-rest-framework)
body: <p>I am trying to determine the best way to add a root element to all json responses using django and django-rest-framework.</p>
  
  <p>I think adding a custom renderer is the best way to accomplish what I want to achieve and this is what I have come up with so far:</p>
  
  <pre><code>from rest_framework.renderers import JSONRenderer
  
  class CustomJSONRenderer(JSONRenderer):
  #override the render method
  def render(self, data, accepted_media_type=None, renderer_context=None):
      #call super, as we really just want to mess with the data returned
      json_str = super(CustomJSONRenderer, self).render(data, accepted_media_type, renderer_context)
      root_element = 'contact'
  
      #wrap the json string in the desired root element
      ret = '{%s: %s}' % (root_element, json_str) 
  
      return ret
  </code></pre>
  
  <p>The tricky part now is dynamically setting the <code>root_element</code> based on the view that <code>render()</code> is being called from.</p>
  
  <p>Any pointers/advice would be greatly appreciated,</p>
  
  <p>Cheers</p>