Introduction to Using Django
Tags: python, webdev, beginners, django
Published: 2023-12-27 17:47:39

In this article, I will explain the basics of what Python's Django is, how it is used, and its benefits and pitfalls. As a primarily SERN stack developer, I was interested in exploring Django because of its all encompassing nature. There are a handful of JavaScript libraries and/or frameworks you would need in your stack to make up the functionality offered by Django, but with built in functionality comes trade offs, so let's dive in!

## About Django
**How it started**
Django was built out of necessity by developers at World Online, an online newspaper in Lawrence, Kanasas, in 2003 and released in 2005. Developers, Adrian Holovaty and Simon Willison, created Django (pronounced **JANG**-oh) because World Online was responsible for building complex web applications on very short, journalism turn arounds. To keep up, they began to extract a generic framework from their previously build applications, and so Django was born.

**What it is**
Django is an open source, full stack web development framework that follows an Model-View-Template (MVT) Framework. It provides features to build out both front and back end application components, utilizing SQLite for its DBMS and ASGI or WSGI for server options. It promises to make building website faster, safer, more scalable, and more versatile, and touts it is the web framework for perfectionists with deadlines. 

**The Framework**
Its MVT framework confuses many as it appears to be a renamed version of the classic MVC, but Django details the difference explaining that they interpret the “view” to describe _which_ data gets presented to the user, not what _how_ the data is presented, leaving the how as the responsibility of the "template". The "model" functions similarly to what you would expect. It is where data is provided from the database using an ORM that is built into Django. Some may still ask, where the controller fits into the picture, and they explain that the framework itself acts as the controller through the URL configuration. 

Now that we have an understanding of the framework's structure, take a look at the below diagram for a visual understanding of how data is passed.

![Django data flow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jj8fb350rd2tamko9p3.png)
_Image source: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Introduction_

Just as in other frameworks, this structure dictates the project and application file make up. A Django directory is made up of an overall project directory with one or more app directories included within the project. They delineate the difference between a project and apps describing apps as web applications that "do something" and projects as the larger container that houses multiple apps. This allows be continued reusability of code by separating functionality. 

## Benefits and Pitfalls
Python comes with many out of the box features like authentication, database connection, ORM, and database admin interface to name a few. In addition to these features, it is also known for its in-detail documentation and robust community. Because of this, it has gotten a reputation for being a go to choice for beginners and database driven sites, but that does not mean it doesn't come with its own set of downfalls. 

**Benefits**
First, let's explore its benefits. As a developer new to Python development, I can attest to its impressive documentation and ease of use. With only a few commands you can have a simple, full stack application set up in minutes. Along with documentation, its tutorials walk you through step by step creating a basic application. Additionally, database connection is done in seconds with a few commands, and a database administration interface can also be built out in the matter of a a few commands. These benefits are why Django has gained popularity because much of the set up and configuration is abstracted away, leaving the developer more time to work on actual functionality.

**Pitfalls**
Just as with most things, where there are pros, there are cons. Although Django has a reputation for being quick to set up, its runtime speed can often be a pitfall if your application is not well optimized. Because of the amount resources being accessed in the framework and the application's architecture, sites can run slowly, but this can be accounted for if you have optimization top of mind from the beginning. Additionally, Django is not always the best choice for every project. Because the backbone of the framework is built around different views that are served based on the url configuration, it is not always the best choice for smaller, one-page applications.

## In Conclusion
I hope this article provided some context before you begin on your Django journey. Before embarking, map out your the architecture of your site to ensure Django is the best option and that you are developing with optimization in mind. Then, I suggest checking out [Django's website](https://www.djangoproject.com/) for details on how to start a project. As mentioned previously, its documentation and community is one of its best benefits for new developers. 

## Sources
https://www.djangoproject.com/
https://www.w3schools.com/django/django_intro.php
https://careerfoundry.com/en/blog/web-development/django-framework-guide/