0% found this document useful (0 votes)
13 views2 pages

DRF Easy Level Notes

Django REST Framework (DRF) is a toolkit for building APIs in Django, allowing data exchange in JSON format. Key components include serializers for data conversion, viewsets for CRUD operations, and routers for URL pattern generation. The framework also supports features like authentication, throttling, pagination, and a browsable API for easier testing.

Uploaded by

Radha Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

DRF Easy Level Notes

Django REST Framework (DRF) is a toolkit for building APIs in Django, allowing data exchange in JSON format. Key components include serializers for data conversion, viewsets for CRUD operations, and routers for URL pattern generation. The framework also supports features like authentication, throttling, pagination, and a browsable API for easier testing.

Uploaded by

Radha Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Django REST Framework (DRF) - Beginner Notes

1. What is Django REST Framework (DRF)?

DRF is a toolkit to build APIs in Django. It helps your Django app talk to other apps by sending and

receiving data (usually in JSON format).

2. How do you install DRF in a Django project?

Use pip: pip install djangorestframework. Then add 'rest_framework' in INSTALLED_APPS in

settings.py.

3. What is a serializer in DRF?

A serializer converts Django model objects into JSON and vice versa. It acts like a translator.

4. What's the difference between Serializer and ModelSerializer?

Serializer: Define fields manually. ModelSerializer: Auto-creates fields from a model.

5. How do you create a simple API view using @api_view?

Use the @api_view decorator to define allowed methods like GET, and return a Response object.

6. What is the purpose of APIView?

APIView lets you write class-based API views using methods like get(), post(), etc.

7. What is a viewset in DRF?

A viewset groups all CRUD operations into a single class.

8. How does a ModelViewSet work?

It creates a full CRUD API with just a model and serializer.

9. What is the role of router in DRF?

Routers auto-generate URL patterns for viewsets.

10. What is the use of @action decorator in viewsets?

@action lets you define custom actions like /users/5/activate/.

11. How do you perform CRUD operations using DRF?

Use POST to create, GET to read, PUT/PATCH to update, DELETE to remove.


12. How do you return JSON responses using DRF?

Use the Response class to return Python dictionaries as JSON.

13. What is the purpose of Response object in DRF?

It wraps data and returns it with a proper status code.

14. What is status in DRF used for?

DRF provides readable status codes like HTTP_200_OK, HTTP_404_NOT_FOUND.

15. What are throttling and pagination in DRF?

Throttling limits requests. Pagination breaks large results into pages.

16. What is the default authentication method in DRF?

SessionAuthentication and BasicAuthentication are default.

17. How do you enable basic authentication in DRF?

Set DEFAULT_AUTHENTICATION_CLASSES in settings.py to include BasicAuthentication.

18. What is the difference between GET, POST, PUT, and DELETE in DRF?

GET = Read, POST = Create, PUT/PATCH = Update, DELETE = Remove.

19. What is BrowsableAPIRenderer?

It makes the API look nice in the browser with forms for testing.

20. How do you disable the browsable API?

Set DEFAULT_RENDERER_CLASSES to JSONRenderer only in settings.py.

You might also like