Quick Contact

    Python Tutorial
    Python Panda Tutorial
    Python Selenium
    Python Flask Tutorial
    Python Django
    Numpy
    Tensorflow
    Interview Questions & Answers

    Django Request-Response Cycle

    All backend technologies and web APIs are based on one system that is The Request-Response Cycle. The system is responsible for data interchange between client and servers. Even the new technologies based on micro-services use the Request/Response cycle.

    Request/Response objects are transmitted over the web. Content like images, HTML, CSS, JavaScript is all Response Objects.

    How does Web Work?

    It’s simple yet a very important aspect to understand. So, basically, any application over the internet works by passing information. This information is often passed as objects. The objects mentioned here comprises of various files or properties. These objects can contain files as attachments.

    It is a very similar concept to emails.

    HTTP

    These interchanges between various servers and client machines following a set of rules. That set of rules is called HTTP. HTTP stands for HyperText Transfer Protocol. It’s simply a set of rules, a common standard followed by devices to connect to each other over the internet.

    The information sent or received is given the name of request and response.

    Request Objects contain the request made by the client. The server responds with the appropriate information according to Request Object.

    On the other hand, the Response Object is information served by the server to the client. It all makes sense now? Wait, there’s still more:

    The below figure clearly explains how the web works. Well, it does that on a very high-level perspective. In this figure, both the client and server are using HTTP. If both of them don’t have the same protocol, the connection can not be done.

    Request

    Now, it’s time to understand Request. The requests are smaller in size than response. Basically, a Request is a “request made by the client” to the server. Any URL that gets searched is a request.

    But, that’s not the only type of Request. Request objects also give information to the server. The forms we fill, the images we upload to the server are also Requests. When we upload this information, it is transferred as attributes of the Request object.

    The server can then access that information and call its own functions.

    Response

    Responses are generally heavier in bandwidth than Request. The Response objects usually contain HTML, CSS, JavaScript, image, video files, etc. There are other files as well, which can be served by the server as a response. Response objects also have various parts.

    This is the response object we actually get from the server. It has various parts to it. The response object we are discussing has 5 headers. Any response or request objects have a part to them called HTTP headers. These HTTP headers contain various information regarding the response.

    Django Request-Response Cycle

    Django’s handling of Http Requests and Response is unique in its own ways.

    Django can be considered as an application on the server. Its main task is to process the request received by the server. Then it calls functions and provides a response. This is a brief of how Django interprets Request and provides Response.

    Whenever a request comes into Django, it is handled by middlewares. When the Django server starts, the first thing it loads after settings.py is middlewares.

    The Request is processed by various middlewares one at a time. So, from the above list, when the request comes it will be passed through the security middleware. If it deems it to be unhealthy, then it will not let the request go any further.

    Once, we get a matching URL, the corresponding view function is called. The view function will get various attributes and other URL parameters. Also, the view function will be able to access files from the requests. These Requests are considered to be HttpRequest class objects.

    The requests module is a Python module that provides various methods for Request objects.

    Once, the view function has been executed, it’s time to give a response. The response is given in the form of HttpResponse. The response is not limited to that. The Response can be PDF, JSON, CSV. That is one of the features of Django. It provides built-in support to provide responses of various types.

    When the response is a render, it will look for the HTML. The HTML page to be the server is processed by DjangoTemplating Engine. Once that completes, the Django simply sends the files as any server would. That response will contain the HTML and other static files.

     

    Apply now for Advanced Python Training Course

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.