Django Web Framework and its MVT architecture

Django Web Framework and its MVT architecture

My first experience with Django was very challenging, maybe because I needed to use this web framework to develop an e-commerce website quickly in one of my projects. I’ve been writing in python for a while now and then I thought Django would be easy to understand.

Sometimes it can be overwhelming when you see a lot of files and you begin to wonder why the project is structured in the way it is. A good understanding of the Django framework and its MVT architecture is very important in developing web apps.

In this article, you will learn about web frameworks and their purpose, Django framework and why it is used by many developers in back-end web applications and then finally I will talk about the Model-View-Template architecture.

Table of Contents

What are Web Frameworks and their purpose?

Django framework and its benefits?

MVT architecture

Conclusion

What is a Web Framework?

Before you start reading about Web Frameworks, let’s begin with defining what software frameworks are. Frameworks are templates developers use to build applications especially when they do not want to start from scratch.

So frameworks help us to focus on the elements of the projects rather than what is going on underground thereby speeding up the development process. If it helps, you can think of a framework consisting of the words Frame + work, a Frame can be something that sets a boundary or encompass a space, like your photo frame, your picture won’t go out of the frame, right? So a software framework entails all the work you do within the boundaries or the standard provided by that framework.

A web framework is no different, it provides a standard way to build and deploy Web applications. Most web frameworks are based on the Model-View-Controller (MVC) pattern which separates a large application into specific sections i.e presentation logic, business logic and data access logic. So, web frameworks provide a pre-defined process or guideline to facilitate web development.

Django Framework and Its benefits

Have you ever opened an E-commerce website and seen cool features like a shopping cart? Or even used the chat and call functionality on social media apps? These systems can be implemented using python’s web framework, Django. Django is high-level ( meaning it’s user-friendly with abstraction from the details of the computer architecture), free, open source and facilitates fast development of secure and easy-to-maintain websites. Django was first created by web programmers at Lawrence Journal-world newspaper, it has since then been developed and maintained by Django Software Foundation. Many developers use Django because it provides speed, security, and scalability, which means you can pick up a project from idea to production in a short time. Django has many features which you can use in developing a dynamic website having user authentication, database manipulation, security, and so on. There are other Python frameworks like flask but if I need to build a website that interacts with a database and I'm trying to do this quickly then I would go for Django.

Django's MVT Architecture

MVT is a software design for developing applications, it is a collection of three components Model, View, and Template. Django framework consists of an Object-relational mapper which enables interaction between Models and Databases, a procedure for processing HTTP requests, and a URL dispatcher.

Model

A model is a class that represents a table in our database. The model maintains the whole application data and also facilitates reading, updating, adding and deleting data in the database

View

Views are python functions that receive HTTP requests, process them, and return an HTTP response. A view is the Python callback function for a particular URL, it describes which data is sent back to the client.

Template

Templates are text files that define the layout of the user interface. Its purpose is to make writing dynamic pages easier since python codes can be written in HTML files, Django template helps to separate the design from the python code and allows us to build dynamic web pages.

Conclusion

Django is very popular in backend development when you are looking to transition from static websites to web apps where you can store data in a database, and provide user access and you want to do this quickly then you will most likely be using the Django web framework.

Thanks for reading my article. Say hi to me on Twitter @Sammie_savvie