[Django]-How I can change render to return json in view Django

9👍

Use JsonResponse

from django.http import JsonResponse
..
def articleTheme(request):
    ..
    return JsonResponse({'newTheme': theme })

0👍

You can return the data with HttpResponse and in JSON format like this:

data = {'newTheme': theme}
data = json.dumps(data, cls=DjangoJSONEncoder)
return HttpResponse(data)

Leave a comment