DEV Community

Mageshwaran
Mageshwaran

Posted on

Django For Beginners - Life Cycle P2

Alt Text

When client sends a request(http synchronous) and waits for a response from the service, a lot happens in the server side, server will get the request and process it and return the response to the client.

Alt Text

Note 1

When client made a request, it will be sent to the server like Nginx(in development, django will use the default development server), then it will connect to the wsgi(standard interface for communication between an application and the web server) module in django to talks to the django project

Note 2

Then the request will be send through the middleware, django has its own premade middleware for things like authendication, session and many more. Middleware is like a gatekeeper, request has to cross each one in order and vice versa. you can even write your own custom middleware.

Alt Text

Note 3

urls is the router in django, django will look for the requested url and calls the view

Note 4

view in django where the logic will be written, view will get the requesting data and process it, queries the model and return back the HttpResponse as template or any other format like json, xml. view is the place where you work, most of the time to build the logic for the application.

Note 5

Templates in django are normal html files with extract features included, it will be send to client as html file pre rendered in the server. Template can be reused in another templates by including it (like reactjs component).

Note 6

Response has to cross the Middleware in the reverse order, check Note 2. you can validate the response or do any kind of validation in the response middleware.

Thanks you, have a great day ahead.😎

Top comments (0)