Django interview questions start with the basics: how does a request reach a view, and how does the ORM get data? As you gain experience, the questions move to slow queries, safe data changes and systems that fail under load.
These 25 Django interview questions and answers use one example, a course booking app, so the ideas connect. If the request flow is new to you, use the Django tutorial first.
What Django interview questions cover
| Level | Know well | Be ready to show |
|---|---|---|
| Fresher | Models, views, URLs, forms | A working CRUD app |
| 2 to 4 years | ORM, APIs, tests | A query you improved |
| 5 years | Scaling, data safety, operations | A design and its risks |
Job roles differ, but data handling appears at every level.
Django interview questions and answers for freshers
The first 11 are Django interview questions for freshers. Use your own project as an example after each short answer.
Q1. What is Django, and why use it?
30-second answer: Django is a Python web framework. It includes an ORM, admin site, authentication, forms and security tools, so a team does not need to build them from zero.
It suits database-driven sites and APIs. A tiny service may prefer a smaller tool. Compare it with other stacks in Spring Boot vs Django vs Express.
Q2. What is the MVT pattern?
30-second answer: The model manages data, the view handles the request and the template creates HTML. Django's URL system chooses the view.
Django's view is close to a controller in MVC. Its template is close to an MVC view. The names differ, but the goal is the same: keep data, logic and display apart.
Q3. Follow one request through Django.
30-second answer: A request enters through WSGI or ASGI, passes through middleware, matches a URL and reaches a view. The view may use models and returns a response. The response travels back through middleware.
Mention both middleware directions. It shows that you know the whole path.
Q4. What is the difference between a project and an app?
30-second answer: A project is the complete site and its settings. An app is a Python package for one area, such as courses or payments. A project can contain many apps.
Keep an app focused. One app for the whole company becomes hard to change. For our example, courses, bookings and payments could be three apps, each with its own models and tests.
Q5. How do models and migrations work together?
30-second answer: A model describes data in Python. makemigrations writes a change file and migrate applies it to the database.
from django.db import models
class Course(models.Model):
name = models.CharField(max_length=100)
seats = models.PositiveIntegerField(default=0)
def __str__(self):
return self.name
Commit migration files so every environment can make the same change.
Q6. What is the difference between null and blank?
30-second answer: null=True allows a database NULL. blank=True allows an empty value in validation.
For normal text, prefer an empty string and avoid having both NULL and an empty string mean "no value". A unique optional text field is one useful exception.
Q7. What do the on_delete options do?
30-second answer: They decide what happens when the related row is deleted. CASCADE deletes dependants, PROTECT stops the deletion and SET_NULL clears the link if null is allowed.
Use PROTECT if deleting a course must not erase its bookings. The right choice depends on which records the business must keep.
Q8. What is a QuerySet, and when does it run?
30-second answer: A QuerySet represents a database query. It is lazy, so building or filtering it does not normally run SQL. Looping, converting to a list or calling count() does.
courses = Course.objects.filter(seats__gt=0) # no SQL yet
courses = courses.order_by("name") # still no SQL
names = list(courses) # SQL runs
Q9. What is the difference between get and filter?
30-second answer: get() returns one object and raises an error if there are zero or many. filter() returns a QuerySet, which may be empty.
For a web page, get_object_or_404() changes a missing row into a 404 response.
Q10. How does Django protect forms from CSRF?
30-second answer: Django checks a secret token on unsafe requests such as POST. A normal attacking site cannot read the token and send a valid request in the user's session.
Use {% csrf_token %} inside internal POST forms. CSRF protection does not replace login or permission checks.
Q11. When would you use a function view or a class view?
30-second answer: A function view is direct and easy for custom logic. A class view helps when methods and behaviour need reuse. Generic class views cover common lists and forms.
Pro tip: Do not call class views "better". Say which one makes the particular code easier to read.
Django interview questions and answers for experienced professionals
From here, explain the problem before naming a feature.
Q12. What is the N+1 query problem?
30-second answer: One query gets a list, then one extra query runs for each item. Use select_related for single relations through a SQL join and prefetch_related for many relations through extra queries joined in Python.
bookings = (
Booking.objects
.select_related("student", "course")
.prefetch_related("payments")
)
Here each booking has one student and one course, but many payments. Check the query count in a test. Fetching relations you do not use also wastes work.
Q13. What do F and Q objects do?
30-second answer: F refers to a database field. Q joins conditions with OR, AND or NOT.
from django.db.models import F, Q
Course.objects.filter(
Q(name__icontains="java") | Q(seats__lt=F("limit"))
)
This example assumes Course also has a limit field. The comparison happens inside the database.
Q14. How do annotate and aggregate differ?
30-second answer: annotate() adds a calculated value to each row or group. aggregate() returns a dictionary for the whole QuerySet.
Use annotate for bookings per course and aggregate for total bookings. Be careful when joining several many relations because joined rows can make counts too high.
Q15. How do you prevent two users from booking the last seat?
30-second answer: Lock the course row inside a transaction, check the seats and then save the booking. A normal read followed by a write leaves a gap.
from django.db import transaction
@transaction.atomic
def book(course_id, student):
course = Course.objects.select_for_update().get(pk=course_id)
if course.seats == 0:
raise ValueError("No seats")
course.seats -= 1
course.save(update_fields=["seats"])
return Booking.objects.create(course=course, student=student)
Row locking depends on the database. Django's SQLite backend ignores select_for_update().
Q16. What can go wrong with signals?
30-second answer: Signals hide work, so a save may trigger code the reader cannot see. They may also run twice if registered twice.
Use them when separate apps need loose contact. Prefer a clear service function for an important booking flow. Remember that QuerySet update() and bulk_create() do not send each model's save signals.
Q17. What is middleware order, and why does it matter?
30-second answer: Request work runs from top to bottom. Response work runs from bottom to top. A middleware that needs request.user must come after authentication middleware.
Keep middleware for rules that affect many requests. One feature's business rules belong elsewhere.
Q18. How does a DRF serializer work?
30-second answer: It changes input data into validated Python values and changes objects into data for a response. A ModelSerializer can create fields from a model.
Put field rules in validate_<field>() and rules across fields in validate(). Still keep critical uniqueness rules in the database.
Q19. How do authentication, permission and throttling differ in DRF?
30-second answer: Authentication identifies the caller. Permission decides whether the caller may act. Throttling limits how often they call.
For a list, also filter the QuerySet to rows the user may see. Object permission checks do not automatically hide every list row. The REST API guide explains the request basics.
Q20. How do you test a Django view?
30-second answer: I create test data, use Django's client, send a request and check the response plus the saved result. I also test a user without permission.
from django.test import TestCase
class CourseListTests(TestCase):
def test_page_loads(self):
response = self.client.get("/courses/")
self.assertEqual(response.status_code, 200)
This assumes that the project maps the courses URL. Use assertNumQueries for an important list.
Interview note: A test that only checks "not 500" proves very little. Check the rule the user cares about.
Django interview questions for 5 years experience
These five questions are scenarios. Start with the safest simple design.
Q21. How would you add a required column to a table in use?
30-second answer: First add it as nullable, then deploy code that writes it, fill old rows in batches, check them and make it required in a later change.
This works while old and new app versions overlap. Review the SQL and possible locks for the actual database. sqlmigrate shows the SQL before it runs.
Q22. How would you speed up a slow endpoint?
30-second answer: I would measure total time, query count and slow SQL. Then I would fix repeated queries, add a suitable index, reduce returned data and cache only if needed.
Show the before and after numbers from your own test. Do not start with a cache because it can hide a bad query. If you add one, say how old data gets removed.
Q23. How would you run email after a booking?
30-second answer: Save the booking first, then queue an email when the transaction commits. Make the job safe to retry.
Use transaction.on_commit() so a rolled-back booking sends nothing. If losing the queue message is not acceptable, save an event row in the same transaction and process it later.
Q24. When would you use async views?
30-second answer: Use them when many requests wait on async input or output, such as several external APIs. They do not make CPU-heavy code faster.
Blocking code inside an async view blocks the event loop. Check that libraries and database work are suitable, and test under ASGI.
Q25. How would you deploy Django safely?
30-second answer: I would set DEBUG to false, protect secrets, configure allowed hosts and HTTPS, run check --deploy, collect static files and manage migrations as a planned step.
Run several app processes behind a web server or load balancer, then add logs, health checks and backups. State how to roll back both code and data changes.
Common mistake: Assuming a code rollback also reverses a database migration. The old code must work with the changed database or you need a separate plan.
How to talk about your Django project
Prepare a two-minute description in this order: the user, the problem, the main models, the hardest rule and one thing you would improve. For the booking app, the hardest rule could be "never sell the same seat twice".
Then prepare for these follow-ups:
- Which page runs the most queries, and why?
- Which user must not see which data?
- What happens if a save fails halfway?
- Which test would catch your worst bug?
If you cannot answer one, open the project and find out. Do not hide a weakness. Saying what is missing and how you would add it is better than claiming a small project is ready for millions of users.
Write down the exact commands you use to start the app, run tests and apply migrations. An interviewer may ask you to share your screen. Clear steps save time and help you stay calm.
How to prepare for Django interview questions
Take one project and trace a request, print its SQL and test a forbidden action. Freshers should do this before learning advanced tools. For experienced roles, prepare one story each about a slow query, a failure and a design choice.
Review Python interview questions and DBMS interview questions. The Python full stack course covers a guided route from language basics to web work.

