Django JSON Data

Implement JsonResponse in Django API for JSON data

Django counts with the built-in JsonResponse class, which is a subclass of HttpResponse. Its default Content-Type header is set to application/JSON, which is really convenient. It also comes with a JSON encoder, so you don’t need to serialize the data before returning the response object.

Here is the short version of how to implement it.

  1. In views.py , make API that would call the JsonResponse for fetching the respective data.

2. Inside the product, in urls.py, call the functions in order to fetch the data in JSON format.

3. In onlinestore, urls.py has to redirect the call to the product routes.

Now, these are the final steps for checking the results, after these steps:

  • localhost:8000/api/products(this will display all the products in json)
  • localhost:8000/api/products/1(this will display data of id=1 in json)

If you want to visit a completely functional code, do visit my Github repo: https://github.com/Poulami96/JsonResponse-Django-

Do give it a try .Trust me its pretty simple and do google if you are stuck anywhere.

--

--

--

Software Engineer(Python,Ex-ISRO)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Scrum Master’s Role: Playing Support

Monads and C#: Enterprise development with (almost) no exception handling

The 0x Ecosystem Acceleration Program’s History & Future

SQL — Explained like you are 5!

How to hit AWS Step Functions limitations…

Over 36,000 KSM Addresses Reserved for Bifrost Kusama Slot Auction | Weekly Report 54

Dual Axis Motors with Smoothieware

Clickable ListView Items with Clickable Buttons

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Poulami Dutta

Poulami Dutta

Software Engineer(Python,Ex-ISRO)

More from Medium

Integrating Github with Postman and Newman

Automation Using AWS Lambda Function, S3 and API Gateway to Control EC2 Server and Send Email

ASP.NET Web API Test Questions and Answers.

Koa JS with REST APIs