🎸 Django Beginner

What is Django REST Framework (DRF)?

Why Interviewers Ask This

This is a classic screening question for Django roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

Django REST Framework (DRF) is the most popular third-party library for building REST APIs with Django. It provides serialization, authentication, permissions, viewsets, routers, and browsable API. Installation: pip install djangorestframework; add "rest_framework" to INSTALLED_APPS. Serializer: converts complex data (querysets, model instances) to Python primitives (serializable to JSON/XML): from rest_framework import serializers class ArticleSerializer(serializers.ModelSerializer): author_name = serializers.CharField(source="author.get_full_name", read_only=True) class Meta: model = Article fields = ["id", "title", "content", "author_name", "published_at"] read_only_fields = ["id", "published_at"]. ViewSet: from rest_framework import viewsets, permissions class ArticleViewSet(viewsets.ModelViewSet): queryset = Article.objects.filter(is_published=True) serializer_class = ArticleSerializer permission_classes = [permissions.IsAuthenticatedOrReadOnly] def perform_create(self, serializer): serializer.save(author=self.request.user). Router (auto URL generation): router = DefaultRouter(); router.register("articles", ArticleViewSet); urlpatterns += router.urls. This creates: GET /articles/, POST /articles/, GET /articles/{id}/, PUT/PATCH /articles/{id}/, DELETE /articles/{id}/. Authentication: TokenAuthentication, SessionAuthentication, JWT (via simplejwt). Permissions: IsAuthenticated, IsAdminUser, IsAuthenticatedOrReadOnly, custom permissions. Pagination, filtering, throttling — all built-in.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.