Another JsonResponse

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from snippet 800 import json_encode

from django.http import HttpResponse
class JsonResponse(HttpResponse):
    '''Like an HttpResponse, but encodes the data as JSON.
    The file-like operations probably won't do what you want.'''
    def __init__(self, obj, comment=True, **kw):
        json = json_encode(obj)
        if comment:
            # Put the JSON in comments to avoid CSRF issues:
            json = '/* %s */' % json
        super(JsonResponse, self).__init__(json, mimetype='application/json', **kw)

More like this

  1. JsonResponse by zakj 6 years, 1 month ago
  2. JSON encoding middleware by kcarnold 4 years, 11 months ago
  3. Extended JSON encoder by kcarnold 4 years, 11 months ago
  4. ExcelResponse by Tarken 4 years, 6 months ago
  5. jinja2 csrf_token extension by jasongreen 3 years, 4 months ago

Comments

(Forgotten your password?)