Create JsonResponse UTF-8 in Django

3

Is there a simple way to cancel DjangoJSONEncoder.ensure_ascii and put it in False or print text different from ascii in django.http.JsonResponse in any other way?

    
asked by jdederle 20.09.2017 в 03:49
source

1 answer

3

If you tend to use the utf-8 format, instead of Django's JsonResponse () use this form:

return HttpResponse(json.dumps(response_data, ensure_ascii=False),
content_type="application/json")

or this form:

return JsonResponse(json.dumps(response_data, ensure_ascii=False),
safe=False)

More about safe = False see HERE

    
answered by 20.09.2017 / 03:57
source