May 2018
Beginner to intermediate
526 pages
11h 57m
English
REST framework provides an APIView class, which builds API functionality on top of Django's View class. The APIView class differs from View in using REST framework's custom Request and Response objects and handling APIException exceptions to return the appropriate HTTP responses. It also has a built-in authentication and authorization system to manage access to views.
We are going to create a view for users to enroll in courses. Edit the api/views.py file of the courses application and add the following code to it:
from django.shortcuts import get_object_or_404from rest_framework.views import APIViewfrom rest_framework.response import Responsefrom ..models import Courseclass CourseEnrollView(APIView): def post(self, ...
Read now
Unlock full access