I have been assigned a project which has two versions of it: older one is written in django and new one written in django rest framework.
I am quite new to both django and drf. While going through both codebase, I came across following code in one of the views.py in new drf version:
def get_xyz(request):
# some business logic
return HttpResponse(json.dumps({ ... })
, content_type="application/json"
, status=status.HTTP_200_OK)
Then in older version of the app, I found function with exactly same above structure in its views.py. This created following confusions in me:
Can we use function based views (as above) written in (non-drf) django app as it is in drf based app?
Can we use class based views (as shown below) from non-drf django app as it is in the drf based app?
class AbcClass(View): def get(self, request): # business logic return HttpResponse(json.dumps({ ... }) , content_type="application/json" , status=status.HTTP_200_OK) def post(self, request): # business logic return HttpResponse("success", status.HTTP_200_OK)Does all django framework (non-rest) classes (like
Viewabove) work perfectly in drf?Can we make frontend app written in react (or angular) send requests and receive responses from old django app (similar to how frontend apps built with these UI frameworks are usually made to communicate with APIs built in drf)?