Categories
Python Answers

How to create a JSON response using Django and Python?

Spread the love

To create a JSON response using Django and Python, we can use the JsonResponse class.

For instance, we write

from django.http import JsonResponse
return JsonResponse({'foo':'bar'})

to create a JsonResponse instance with a dictionary that we want to return as the response JSON body.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *