Introduction to Django

Web Development with Python

Ishaan Sunita Pandita
5 min readJul 24, 2022
Photo by XPS on Unsplash

Series Content

  1. Introduction to Django
  2. Setting up Django
  3. Building a Django Application
  4. Hiding Secret Keys in a Django Application
  5. Database connectivity in a Django Application
  6. Deploying a Django Application

Introduction

Every day we come across hundreds of web pages, all with different looks, unique purposes and user experiences. As a developer, it is quite intriguing to look at the wonderful and powerful things we can build on the internet, not just for ourselves but also for the world to see and use!

One of the most beautiful aspects of being a developer is that one gets to experience building this stuff by oneself. By diving deep into the What, Why, Where, When and How of web development, we developers gives ourselves the ability to design and present to the world, works of art that are commonly known as websites.

It all comes down to the very basics: HTML, CSS and JS. The Holy Grail of web pages. Everything that you see on the browser can be and is written using these three languages. You can read more about them in this article:

Python in Web Development

You may have heard about Python being used extensively for Data Science, Deep Learning, Machine Learning, Artificial Intelligence and Application Development; however, being the versatile language that it is, there are multiple methods in which Python can be used for Backend Development of websites.

The internet today follows the Client-Server architecture, where the Frontend relates to the stuff which can be seen by the client on their browser, and the Backend is everything that is hidden from the user and often runs on the server side of applications.

Picture Source: Here

Python makes use of frameworks and libraries like Django and Flask to facilitate development of web applications. In this series, we will discuss Django in detail.

Django

Django is a Python framework which enables the developer to create web applications using Python as the Backend Language. You can read more about the origins and purpose of Django on their official website:

We will discuss some fundamental features which Django offers to developers in this article:

  • The MVT Structure
  • The ORM facility
  • Built-in functions and models
  • Built-in admin features

MVT Structure of Django

There are 2 broad classifications of web development frameworks based on the development structure they offer:

MVC Structured Frameworks and MVT Structured Frameworks. Django offers the MVT Structure.

Let us compare the two in brief

MVC Structure:

  • Model: Offers data modeling and logic development capabilities
  • View: Decides what is visible to the end user
  • Controller: Acts as the bridge between Model and View

MVT Structure:

  • Model: Offers data modeling and logic development capabilities
  • View: Acts as the bridge between Model and Template
  • Template: Decides what is visible to the end user

Both structures provide the facility to dynamically update the data which the end user sees on their device.

In Django, the Model section allows connection to database facilities like MySQL, PostgreSQL etc. the View section allows the developer to write down presentation logic, fetch and push data to and from the database and render the same on screen via Templates, which help dynamically display data to the user by essentially using variables and conditional logic in HTML.

ORM in Django

Django earns its title as one of the most powerful web development frameworks in Python partly due to its ORM facility.

ORM stands for Object Relational Mapping. As the name suggests, it enables the linking of Python Classes to Relational Database Tables.

For example:

class Articles(models.Model):
author = models.CharField(max_length=50)
title = models.CharField(max_length=100)
img = models.ImageField(upload_to='pics_folder')
text_content = models.TextField()

The above class will get mapped to a table in the linked database in this manner:

Table Name: appName_className

Table Columns: Class attributes (author, title, img, text_content)
An id column will get added by default if specified in the Django configuration.

Table Rows: One row for each object created of this class

The most interesting aspect of this feature lies in the fact that as the developer, one does not require to write SQL Queries by hand for these operations! Django does it for us, and we just have to type in a couple of commands to set it up for the task.

Built-In functions and Models

Apart from the ability to create our own models like in the example above, Django offers built-in models and functionalities for some common features.

For example, Django offers a User Model and Authentication functions to facilitate user creation, login, logout and authentication.

Similarly, there are other models like Forms, which allow collection of user input, and Groups which facilitate aggregation of users based on permissions they have and pages they can access on the site.

Built-In Administration

Django also offers administrative features and functionality to staff users. There is a prebuilt website for admin users, where they can view site statistics and also perform administrative functions such as creating new users, changing permissions, adding new objects of registered models and much more.

Conclusion

This gives us a brief introduction to what Django is, its features and how we may use it as a tool for web development with Python at the Backend. Of course, there is always more information available in the official documentation, which you can read here.

If you liked the article, consider following me on Medium for more, here.

If you’d like to get in touch, feel free to do so on my socials here.

Read more about Django in the next article in the series!

Thank you for you patience!

--

--

Ishaan Sunita Pandita

Living life and becoming better than who I was yesterday. Oh, and also learning magic so I can turn data into money.