Creating a JSON response using Django and Python

后端 未结 15 2161
温柔的废话
温柔的废话 2020-11-22 06:02

I\'m trying to convert a server side Ajax response script into a Django HttpResponse, but apparently it\'s not working.

This is the server-side script:



        
15条回答
  •  盖世英雄少女心
    2020-11-22 06:40

    Since Django 1.7 you have a standard JsonResponse that's exactly what you need:

    from django.http import JsonResponse
    ...
    return JsonResponse(array_to_js, safe=False)
    

    You don't even need to json.dump your array.

提交回复
热议问题