Django
A Python web framework for building websites and APIs. It connects incoming requests to your code and provides built-in tools for databases, user accounts, and an admin interface.
What Django gives you
A web application needs more than the code that makes it useful: it has to route requests, store data, and often manage users. Django gives Python developers these pieces in one framework. A library usually handles a specific task when you call it; Django also defines the structure in which your code runs. A Django project contains site-wide settings and routing, while its apps can group features such as a catalog or order management.
From URL to response
When a request arrives, it passes through middleware. Unless middleware returns a response early, Django matches the URL path against its configured patterns and calls the matching view. A view is a request handler, not a screen: it receives the request and any captured URL values, then returns an HTTP response. Middleware can also process the response before it goes back to the client.
You may hear Django's design called Model–Template–View (MTV). Models describe data and relationships. Templates control how supplied data is rendered, usually as HTML. Views decide what to do with the request, including whether to query the database or render a template. A JSON endpoint doesn't need a template at all.
Example: a product endpoint
Assume Product is an existing model with a name field. This URL configuration maps an integer product ID to a view that returns JSON:
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from django.urls import path
from shop.models import Product
def product_detail(request, pk):
product = get_object_or_404(Product, pk=pk)
return JsonResponse({'id': product.pk, 'name': product.name})
urlpatterns = [path('products/<int:pk>/', product_detail)]
For /products/42/, the URL pattern passes 42 as pk. The object-relational mapper (ORM) looks up the row by primary key. If the row exists, the handler returns its ID and name; otherwise, Django sends a 404 response.
Where it fits and what to watch for
Django is useful for content sites, business applications, and APIs backed by a relational database. Its built-in admin is a staff-facing interface for managing registered models, not a ready-made customer-facing site. Model changes are another common source of confusion: makemigrations writes migration files that describe changes, while migrate applies migrations to the configured database.
What comes up in interviews
Interviewers often ask you to trace a request or explain why a page runs more database queries than expected. For example, fetching a list of orders and then reading each order's customer can cause an N+1 problem: one query for orders, then one more per order. If customer is a foreign key, select_related('customer') can retrieve the orders and their customers in a single query using a SQL join.