Django Workflow and Architecture

What is Django?

Django is a free and open source web application framework written in Python. A framework is nothing more than a collection of modules that make development easier. They are grouped together, and allow you to create applications or websites from an existing source, instead of from scratch.

When you’re building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website, forms, a way to upload files, etc.

Frameworks exist to save you from having to reinvent the wheel and to help alleviate some of the overhead when you’re building a new site and Django framework is one of them.

The official project site describes Django as “a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.”

Django offers a big collection of modules which you can use in your own projects. Primarily, frameworks exist to save developers a lot of wasted time and headaches and Django is no different.

Django Architecture

Django follows the MVT framework for architecture.

  • M stands for Model
  • V stands for View
  • T stands for Template

MVT is generally very similar to that of MVC which is a Model, View, and Controller. The difference between MVC and MVT here is the Django itself does the work done by the controller part in the MVC architecture. Django does this work of controller by using templates. Precisely, the template file is a mixture of HTML part and Django Template Language also known as DTL.

Benefits of Django Architecture

The Django Framework is based on this architecture and it actually communicates between all these three components without needing to write complex code. That’s why Django is gaining popularity.

This architecture in Django has various advantages like:

  1. Rapid Development: Django architecture that separates in different components makes it easy for multiple developers to work on different aspects of the same application simultaneously. That is also one of the features of Django.
  2. Loosely Coupled: Django has different components which require each other at certain parts of the application, at every instant, that increases the security of the overall website. As the model file will now only save on our server rather than saving on the webpage.
  3. Ease of Modification: This is an important aspect of development as there are different components in Django architecture. If there is a change in different components, we don’t have to change it in other components. This is actually one of the special features of Django, as here it provides us with much more adaptability of our website than other frameworks.
  4. Security: While building high-end web applications, security becomes a very crucial aspect to ponder on. Django understands this concern and provides its best defender to save your efforts.Using click-jacking, cross-site scripting, SQL injections Django builds a strong wall for the application’s safety. User authentication is also an important feature to safely manage user accounts and passwords that Django provides.
  5. Scalable: Scalability can be understood as an ability of an application to work well when the size or volume of the platform increases.Django works effortlessly in this issue. Websites made with Django have the capacity to handle multiple users at a single time. Some popular websites using Django include Spotify, Netflix, YouTube, Mozilla, Quora, etc

Creating A New Project In Django

To start a new Django project, run the command below:

django-admin startproject myproject

After we run the command above, it will generate the base folder structure for a Django project.

Right now, our myproject directory looks like this:

myproject/                  <– higher level folder |– myproject/            
 |    |– myproject/ <– django project folder
 |    |    |– __init__.py
 |    |    |– settings.py
 |    |    |– urls.py
 |    |    |– wsgi.py
 |    +– manage.py
  • manage.py: a shortcut to use the django-admin command-line utility. It’s used to run management commands related to our project. We will use it to run the development server, run tests, create migrations and much more.
  • __init__.py: this empty file tells Python that this folder is a Python package.
  • settings.py: this file contains all the project’s configuration. We will refer to this file all the time!
  • urls.py: this file is responsible for mapping the routes and paths in our project. For example, if you want to show something in the URL /about/, you have to map it here first.
  • wsgi.py: this file is a simple gateway interface used for deployment.

Leave a comment