Django

Django Middleware

Middleware concept, built-in middleware, custom middleware, process_request, process_response, exception handling

18 питань зі співбесід·
Mid-Level
1

What is a middleware in Django?

Відповідь

A middleware is a processing layer that sits between the incoming HTTP request and the Django view, then between the view's response and the outgoing HTTP response. Middlewares allow global modification of requests and responses, adding cross-cutting features like authentication, session management, or CSRF protection.

2

In which Django configuration file should the list of active middlewares be defined?

Відповідь

The list of active middlewares is defined in the settings.py file via the MIDDLEWARE variable, which is a list of strings representing the import paths of middleware classes. The order of middlewares in this list is important as it determines the execution order when processing requests and responses.

3

What is the role of the SecurityMiddleware in Django?

Відповідь

SecurityMiddleware provides several security enhancements for HTTP requests and responses. It handles HTTPS redirection, adds the Strict-Transport-Security (HSTS) header, protects against content sniffing via X-Content-Type-Options, and manages referrer policy. This middleware should be placed at the top of the MIDDLEWARE list.

4

In what order are middlewares executed when processing an incoming request?

5

Which middleware method is called before the view processes the request?

+15 питань зі співбесід

Опануй Django для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно