Sample questions
Question 1Easy
Which DRF permission class lets anonymous users read but allows only signed-in users to write?
- IsAuthenticated
- AllowAny
- IsAuthenticatedOrReadOnly
- IsAdminUser
Answer: C. IsAuthenticatedOrReadOnly
Explanation
IsAuthenticatedOrReadOnly lets everyone use the safe methods GET, HEAD and OPTIONS, and requires authentication for POST, PUT, PATCH and DELETE.
Step-by-step solution
- GET, HEAD and OPTIONS are the safe methods.
- Safe methods are allowed for everyone.
- Other methods require an authenticated user.
Why the other options are wrong
- A. It also blocks anonymous reads.
- B. It lets everyone write, not only signed-in users.
- D. It limits access to staff users.
Tip: OrReadOnly means reads are open.
Question 2Easy
Which DRF class provides full CRUD with one class and a router?
- ModelViewSet
- APIView only
- GenericForm
- CrudView
Answer: A. ModelViewSet
Explanation
Register it with a DefaultRouter to generate list/detail URLs.
Step-by-step solution
- Define queryset and serializer.
- Router adds URLs.
Why the other options are wrong
- B. APIView needs manual methods.
- C.
GenericForm is not a Django class; the correct choice is ModelViewSet. - D.
CrudView is not a Django class; the correct choice is ModelViewSet.
Question 3Easy
Which package is the common toolkit for building REST APIs on Django?
- Flask-RESTful
- Express
- Django REST Framework
- FastAPI
Answer: C. Django REST Framework
Explanation
DRF adds serializers, viewsets, authentication and routers.
Step-by-step solution
- Install DRF.
- Add to INSTALLED_APPS.
Why the other options are wrong
- A. Different framework.
- B. Node.
- D. Different framework.
Question 4Easy
A DRF view returns Response(data) without a status argument. Which HTTP status does the client get on success?
- 201 Created
- 204 No Content
- 302 Found
- 200 OK
Answer: D. 200 OK
Explanation
Response uses status 200 when none is given. Pass status=201 explicitly when a view creates a new object.
Step-by-step solution
- No status argument was passed.
- Response uses its default, which is 200.
- Pass status=201 for creates.
Why the other options are wrong
- A. 201 is sent only when you pass it explicitly.
- B. 204 is for success with no body.
- C. 302 is a redirect, and nothing here redirects.
Tip: Default is 200; ask for 201 on creates.
Question 5Easy
Which decorator turns a function into a Django REST Framework view that accepts only the HTTP methods you list?
- @require_GET
- @route(method='GET')
- @api_view(['GET'])
- @rest_view('GET')
Answer: C. @api_view(['GET'])
Explanation
DRF's api_view wraps a function view, takes the allowed methods as a list, and gives the function DRF's Request and Response objects. Django's require_GET only restricts the method and does not give DRF's request handling.
Step-by-step solution
- api_view takes the list of allowed HTTP methods.
- It wraps the function so it receives DRF's Request object.
- A method not in the list gets a 405 response.
Why the other options are wrong
- A. A Django decorator that does not provide DRF's Request and Response objects.
- B. There is no such DRF decorator.
- D. There is no such DRF decorator.
Tip: Function views in DRF start with @api_view.
Question 6Medium
What does a DRF serializer do?
- Renders HTML templates from model data and sends the finished page to the browser
- Runs migrations
- Manages sessions
- Converts model instances to JSON-friendly data and validates incoming data
Answer: D. Converts model instances to JSON-friendly data and validates incoming data
Explanation
ModelSerializer builds fields from a model.
Step-by-step solution
- Instance in.
- Data out.
Why the other options are wrong
- A. Templates do that.
- B. Migrations are run by manage.py migrate, not by serializers.
- C. Sessions are handled by the session middleware, not by DRF serializers.
Question 7Medium
A serializer is created with an existing model instance and new data, and then .save() is called. Which method does DRF call?
- create(validated_data)
- update(instance, validated_data)
- to_representation(instance)
- run_validation(data)
Answer: B. update(instance, validated_data)
Explanation
save() calls update() when the serializer was given an instance, and create() when it was not. update() changes the instance's fields from validated_data and saves it.
Step-by-step solution
- save() checks whether an instance was passed in.
- An instance was passed, so it calls update(instance, validated_data).
- create() is used only when there is no instance.
Why the other options are wrong
- A. create() is used only when no instance is passed.
- C. That turns an object into output data; it does not save anything.
- D. That validates the input; it does not write to the database.
Tip: instance given means update; no instance means create.
Question 8Medium
A client calls /api/items/?limit=10&offset=20. Which DRF pagination class reads those parameters?
- LimitOffsetPagination
- PageNumberPagination
- CursorPagination
- Paginator
Answer: A. LimitOffsetPagination
Explanation
LimitOffsetPagination reads limit (how many items) and offset (how many to skip). PageNumberPagination uses page and page_size, and CursorPagination uses an opaque cursor.
Step-by-step solution
- limit sets how many items to return.
- offset says how many items to skip.
- That pair is LimitOffsetPagination.
Why the other options are wrong
- B. It reads page and page_size, not limit and offset.
- C. It uses an opaque cursor parameter, not offset.
- D. Django's core Paginator is not a DRF pagination class that reads query parameters.
Tip: limit and offset go together.
Question 9Hard
What does is_valid(raise_exception=True) do in a DRF serializer?
- Saves the object automatically and then raises an error when no field is changed
- Raises a ValidationError that DRF turns into a 400 response
- Returns a 500
- Skips validation
Answer: B. Raises a ValidationError that DRF turns into a 400 response
Explanation
It keeps view code short.
Step-by-step solution
- Validate.
- 400 on failure.
Why the other options are wrong
- A. Save is separate.
- C. It becomes 400.
- D. It validates.
Practise all 9 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →