Interview questions

Frequently asked questions with concise model answers. Try answering aloud before expanding.

What is the Django ORM's N+1 problem? Medium

Looping over objects and accessing a related field triggers one query per object. Fix with select_related (FK/OneToOne JOIN) or prefetch_related (separate query for M2M/reverse FK).

How does Django protect against common attacks? Medium

Auto-escaping templates (XSS), CSRF tokens, parameterised ORM queries (SQL injection), clickjacking headers, secure password hashing, and security settings like HSTS and secure cookies.

Explain middleware. Easy

Middleware are hooks that process every request/response globally — e.g. sessions, authentication, CSRF, security headers. They run in order on the request and in reverse on the response.