84 Django interview questions with answers
84 Django interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All Django interview questions
What is Django and when should you choose it?
How is Django's MVT different from MVC?
How are a project and an app different in Django?
How do you manage `settings.py` across environments (dev/staging/prod)?
What is `manage.py` and which commands are used most?
How do models and migrations relate in Django?
What does "lazy" QuerySet mean and where does it usually cause bugs?
How do `select_related` and `prefetch_related` differ?
When should you use `transaction.atomic()` and where do you put it?
How do you use `F()` and `Q()`, and what problems do they solve?
What are `abstract = True`, `Meta`, and proxy models for?
When should you write a custom Manager, custom QuerySet, or drop to raw SQL?
How are FBVs and CBVs different, and when do you use each?
How does URLconf work and how should you organize `urls.py`?
How do generic CBVs (`ListView`, `DetailView`, `CreateView`) save code?
How do `@login_required`, `@permission_required`, `@require_http_methods` work?
When should you write a Mixin for a CBV, and how do you avoid breaking the MRO?
When do `HttpResponse`, `JsonResponse`, and `StreamingHttpResponse` differ?
How is Django Template Language different from Jinja2?
How are `Form` and `ModelForm` different, and when do you pick each?
What attack does Django's CSRF token defend against, and how do you use it?
In what order do `is_valid()`, `clean_<field>`, and `clean()` run during form validation?
What is Django middleware and what is it for?
What are the steps of a request's lifecycle through Django?
Why does the order in `MIDDLEWARE` matter, and what bugs come from getting it wrong?
How does async middleware work in Django and what are the common pitfalls?
What does `django.contrib.auth` provide out of the box?
How are `AbstractUser` and `AbstractBaseUser` different when creating a custom user model?
How do Permission, Group, and object-level permission work?
Session, Token, or JWT — which one do you pick for a Django project?
What is Django REST Framework (DRF) and what does it solve?
How are `Serializer` and `ModelSerializer` different?
How do ViewSet and Router save code?
How do Authentication and Permission combine in DRF?
Three pagination styles in DRF — which to pick when?
What is throttling for in DRF, and how do you configure it effectively?
What trade-offs come with writable nested serializers, and how do you handle them?
How do signals (`post_save`, `pre_delete`, ...) work?
When should you NOT use signals, and what should you use instead?
How do you integrate Celery into Django for background tasks?
Celery, RQ, django-q, Huey — which task queue should you pick for Django?
How does the N+1 query problem show up in Django and how do you catch it?
How do you declare indexes in a Django model, and which columns deserve them?
What cache levels does Django's cache framework provide and how do you use them?
What happens if `DEBUG = True` leaks to production?
How does the Django ORM protect against SQL injection, and when does it still leak?
How do WSGI and ASGI differ, and which does Django use?
How do you configure Gunicorn workers effectively?
When do you use async views in Django, and what are the ORM pitfalls?
How are static files and media files different, and how do you deploy them properly?
When should you use `bulk_create`, `bulk_update`, `QuerySet.update()` instead of looping `save()`?
How do `.values()`, `.values_list()`, `.only()`, `.defer()` differ?
When do you use `select_for_update()` to avoid race conditions?
When two branches each create a migration, how does it conflict and how do you resolve it?
How do `get_object_or_404`, `Http404`, `redirect`, and `reverse` fit together?
How do `TestCase`, `TransactionTestCase`, and `Client` work in Django testing?
How do you neatly add filter, search, and ordering in DRF?
What API versioning styles does DRF support, and which should you pick?
How do you set up CORS in Django so an SPA can call the API?
What problem do `CONN_MAX_AGE` and PgBouncer solve when deploying Django?
What security settings are mandatory when deploying Django to production?
Customizing Django Admin: how do `list_display`, `list_filter`, `inlines`, `actions` work?
How do `get()` and `filter()` differ in the Django ORM?
How do `null=True` and `blank=True` differ on a model field?
ForeignKey, OneToOneField, ManyToManyField — when do you use each?
Django calls its architecture MVT — how does it map to classic MVC?
What is a context processor, and what is it for?
How does Django template inheritance work (`{% extends %}` / `{% block %}`)?
What is the difference between `aggregate()` and `annotate()`?
To check whether a QuerySet has data, should you use `exists()`, `count()`, or `len()`?
When dispatching a Celery task, should you pass the model instance or just the id?
`APIView`, generic views (`ListCreateAPIView`), or `ViewSet` — which should you use?
Is `get_or_create()` safe when two requests run concurrently?
How do you prefetch a relation but only load a subset of the child rows?
In what order does DRF serializer validation run? How do `validate_<field>` and `validate()` differ?
Why does a Celery task dispatched from `post_save` fail to find the row that was just created?
How do you write a data migration properly, and why must you not import the model directly?
How do you correctly invalidate cached read-heavy data in Django?
A Celery task calling a payment API hits a network error — how do you design retries so the customer is not charged twice?
Why does `annotate()` with two `Count()` calls return inflated numbers, and how do you fix it?
What does `values().annotate()` group by, and why can adding `order_by()` break the result?
What options does `select_for_update()` take, and what goes wrong under high load?
How do you add a `NOT NULL` column to a table with tens of millions of rows in production without downtime?
What are the risks of overriding `get_queryset()` on the default manager to filter soft-deleted rows?