Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Rest Framework or JsonResponse

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 ?

like image 393
Cai HaiBin Avatar asked Sep 23 '17 01:09

Cai HaiBin


1 Answers

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

like image 176
PoDuck Avatar answered Nov 01 '22 09:11

PoDuck