Life Cycle of Django

Life Cycle of Django

Request - Response life cycle in Django

 Thebasic principle of http protocol is the client sends a request to the server based on the request data, and the server sends a response to the client. We need a webserver and WSGI server while setting up the Django application .Webserver helps us serving static files &content. If it is not served by the web server static files, then it has to served by the WSGI server, which results in more num of request to the server. So gradually slow down the application performance web server balance request load on the server. So highly recommended using the webserver. 

A client can be known as a piece of software that can send a request by following the HTTPS/HTTP. In general terms, it is considered a web browser. We are using one of the variations of "Nginx, uWSGI and Django" or "Nginx, gunicorn and Django" or "Apache, mod wsgi and Nginx" when deploying the Django framework on the database.

When a request is sent by a client to the 0server that is forwarded to the webserver for the first time, it includes the rules of configuration to forward the request to the WSGI server or to handle it on its own.

Layers in Django Application

There are six layers in Django application

1-Request Middlewares

2-URL Dispatcher(URL Router)

3-Context Processors

4-Views

5-Template Renderers

6-Response Middlewares

The Application middlewares must manage the application when it comes in. Several middlewares we can have. This can be found in the project (settings.py). As handling the application, Django requests middlewares follows the command. Suppose we have middleware requests in order A, B, C, then the request is handled first by middleware A and then B, and then C.Django has a range of generic middlewares. We can also write middlewares of our own or tradition. It will be sent to the URL Router or URL dispatcher after the request handled by the middlewares.

URL Router takes the request from the middleware client, and from the request, it takes the URL Route. The URL router will attempt to match the request path to the available URL patterns based on the URL pathThese patterns of URLs are regular expressions. The request will be submitted to the View associated with the URL after matching the URL path with available URL patterns.

We are now in the Views business logic layer.Views use request and request data (data sent in GET, POST, etc.) to process the business logic.Using the request context processors, after processing the request in the view, it adds the context information that will help Template Renderers make the template to generate the HTTP response

Again, the application must return to the middleware of the Response for processing. Answer middlewares process the request, and before sending it back to the client(Browser), add or change the header/body information. After loading and showing the app to the end-user.

Application Life Cycle

A plan is a total of a large number of applications. That application has a purpose and can be reused for another task, such as the contact form on a website can be an application and can be reused for others. 

Create an Application

We assume we are in the project folder. In our main “myproject1” folder, the same folder then manage.py –

$ python manage.py startapp myapp

We just created myappl application, and like a project, Django creates a “myappl” folder with the application structure

myappl/

   __init__.py
    admin.py
    models.py 
    tests.py
    views.py 

Life Cycle of Django


Related Topics

Django Installation

Django Installation Django development environment consists of installing and setting up Python, Django, and a Database System since Django deals with a web application. Below the statement will guide you through installing Python 3.8.0 and...

2 minutes read.

Django CSRF

Django is a high-level python based web framework. Django is open source and free to use for all. Django provides many features to web developers like scalability, security, rapid development,...

4 minutes read.

Django Tutorial

Django Introduction It is a web application framework written in a python programming language. It based on the MVT( Model View Templet) design pattern. It takes a short time to build an application...

2 minutes read.

Django and React

This article will discuss the overview of Django and React, their advantages, applications, and most importantly, how to implement react in Django. What is Django? Django is a free and open-source web...

6 minutes read.

Django Celery

Django is a python-based web framework. It is an open-source and free-to-use framework. Django uses the Model View Template architecture. Django provides many functionalities to web developers. One of these...

3 minutes read.

Django Logging

Every application developed has some bugs and errors. It is the responsibility of the developers to maintain the application by making it bug-free and error-free. To debug the application code...

5 minutes read.

Django Create App

Django is a Python-based web framework that is based on the Model View Template architecture. In this post, we will go through the installation and setup for our first Django...

4 minutes read.

Django Model

Django Model A template is a class representing a table or collection in our DB and where each class attribute is a table or collection area. In the app / models.py, models are...

6 minutes read.

Django Admin

To manage the content of the website, e.g., adding and deleting posts, web developers need an admin portal on the website. The admin portal allows trusted users, also knows as...

3 minutes read.

Django Channels

Channels is a project that uses Django and adds some functionalities beyond the traditional HTTP by using WSGI and ASGI.  We can use both synchronous and asynchronous requests with ASGI...

5 minutes read.

Django Image Upload

Django is a python based web framework that uses Model View Template as its architecture. Django provides really quick web development with its functionalities. While we are building a website,...

3 minutes read.

Django Create Superuser

For managing the website, we need an Admin while creating the Django application. In order to create the admin user, create superuser command is used. The superuser is called the...

3 minutes read.

Django Messages

Django Framework Django is a framework that can make web applications more accessible and faster. Django is an open-source collection of python libraries, and Django can be used for both the...

6 minutes read.

Django Authentication

Django is an open-source free to use web framework which is based on Python. Django uses Model-View-Template as its architecture. The final version of Django was released in 2008. Django...

4 minutes read.

Django DRF

Django Rest Framework, which is also referred to as DRF, is a very powerful application to build RESTful APIs in a Django application. DRF uses the Django framework. Similar to...

3 minutes read.

Django Create Project

Django is an open-source free to use web framework which is based on Python. Django uses Model-View-Template as its architecture. The final version of Django was released in 2008. Django...

4 minutes read.

Life Cycle of Django

Life Cycle of Django Request - Response life cycle in Django  Thebasic principle of http protocol is the client sends a request to the server based on the request data, and the server sends...

3 minutes read.

Django Project

Django Project Let's start to use it. Each web app you want to build in Django is called a project; and a project is a collection of apps. A software is a series of...

3 minutes read.

Creating View in Django

Creating View in Django    Django views are a key component of the frameworkbased applications.We are using Python function or class at their simplest, which takes up a web query and returns a web response.Views are used to get objects from the server, change objects if needed, render types, return HTML, and much more. Class Based View and Function based Django has two types of views: views based on functions (FBVs) and views based on class (CBVs).Initially, Django began with only FBVs, but then introduced CBVs as a way to model features so we didn't have to write boilerplate (i.e. the same software) code again and again.CBVs would be a way to increase efficiency, so you don't have to write as much code as you can. CBVs are classes of Python at their heart. Django ships with a range of "model" CBVs with pre-configured features that can be reused and often expanded.Then helpful names are given to these classes that explain what kind of functionality they provide.These are often referred to as "universal views" because they provide solutions to specific needs. The classes have a journal View function, or "view" for short, is simply a Python program that uses a web query and returns a web response. This response may include the HTML content of a web page, or a redirect, or a 404 error, or an XML file, or an image, etc. Example: You use a view to create a web page, remember that you need to connect a view to a URL to see it as a web page. Simple View We will create a simple view in myapplication to say “Welocome to django application” See the following view – from django.http import HttpResponse ...

4 minutes read.

How to Implement Multiple User Types with Django

Django Framework: Django is a framework that can make web applications more accessible and faster. Django is an open-source collection of python libraries, and Django can be used for both the...

3 minutes read.