11

I want to make my current more interactive by having ajax that calls for json data, I haven't done anything yet except for research and studying. Here are some things I am not very clear. If JsonResponse and DRF can give the json data i need how is DRF different from JsonResponse ?

Cai HaiBin
  • 173
  • 1
  • 8

1 Answers1

7

Django Rest Framework includes a lot of tools that JsonResponse doesn't have.

JsonResponse is to Django Rest Framework as Flask is to Django. You can do all the things you want with JsonResponse, but DRF gives you a lot of tools to automate many tasks, where JsonResponse would require you to manually do all those things.

Edit to clarify: DRF somewhat mirrors Django's functionality. For instance, to validate data, you can do this in the serializer class in DRF, much like you would validate data in the form class in base Django. You can automagically create serializers from models in DRF by using ModelSerializer classes, which is much like Django's generic views.

On the home page of DRF, the very top explains much of what DRF does, including links to examples and explanations:

Django Rest Framework

PoDuck
  • 1,381
  • 15
  • 38
  • Thanks a lot, this confirms I understand from stuff correctly. You could enumerate some of the common task I could do in JsonResponse manually where DRF could automate it for me, except for converting an object or a querysey into json which looks simple with one or two lines of code – Cai HaiBin Sep 23 '17 at 01:46
  • Thank you for explaining things very clear. Is Django-Graphene apple to apple alternative to DRF? – Cai HaiBin Sep 26 '17 at 01:21
  • 1
    Graphene is an implementation of GraphQL, and while it can act as a replacement to DRF, it has extra features that make it easier to do some kinds of queries. It is a relatively new thing though, and I'm unsure of its readiness to go into production commercially. – PoDuck Sep 26 '17 at 01:58