Questions #1


What is Middleware, what is it for, how is it implemented?



Download 85,32 Kb.
bet13/24
Sana06.07.2022
Hajmi85,32 Kb.
#752107
1   ...   9   10   11   12   13   14   15   16   ...   24
Bog'liq
interview en

What is Middleware, what is it for, how is it implemented?
Middleware is a special object that modifies an incoming request or outgoing response. For example, adds headers, makes preliminary checks. Middleware is needed when all application requests need to be processed.
At the language level, this is an object with process_request and process_response methods. Methods must return the accepted object (request or response) for further processing, or throw an exception if something is wrong. In this case, further processing stops.
To enable Middleware, just add the path to it to the MIDDLEWARE_CLASSES tuple.
What are the main middleware? What are they needed for?

  • SessionMiddleware - session support. Adds a session object to the request

  • CsrfViewMiddleware - Verifies that POST requests are from the current domain

  • AuthenticationMiddleware - Authorizes the user. Adds a user field to the request

  • MessageMiddleware - sends short messages to the user

  • Describe the algorithm of auth middleware, user recognition

Describe how the CSRF middleware works
For each request, the system generates a unique token and sets it in cookies. Each form contains a hidden csrf-token field with the same token. When submitting a form using the POST method, Django checks that the form field and the value in the cookie match. If not, it means that the request is forged or sent from another domain.
To free some view from checking (if it is an API, for example), it is enough to wrap it with the csrf_except decorator.
What are signals? Why are they needed? What are the main ones?
Signals are events in the Django ecosystem. Signals are used by subsystems to notify the application of what has happened. To read signals, the programmer registers signal handlers. Signals propagate synchronously. This means that by subscribing a hundred handlers to one signal, we will increase the time required to return a response.
The main signals are the beginning of the request and its end, before saving the model and after, accessing the database.
Important: model signals work individually, that is, for one model. Batch processing such as queryset.all().delete() or queryset.all().update({'foo'=42}) will not fire delete or update events.

  • How to define custom filters for template system?

  • What is ORM? How to organize communication between models in Django?


Download 85,32 Kb.

Do'stlaringiz bilan baham:
1   ...   9   10   11   12   13   14   15   16   ...   24




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish