What **is** Django? 🤷🏼‍♀️

javascriptcoff1

JavaScript➕Coffee🚀

Posted on August 10, 2021

What **is** Django? 🤷🏼‍♀️

So, you know how this goes - someone asked me about a technology that I didn't know much about and...I researched it!

So here we are, all wondering...what is Django (other than a really good and important film)?...what is it for and what does it do? Who uses it?

Only one way to find out...!

First things first: how do you pronounce it?
It's a strange spelling, with a silent D, you pronounce it "Jan"-"go". It's named after a famous jazz guitarist, Django Reinhardt.

From the Django documentation:

The web framework for perfectionists with deadlines.

Sounds interesting but not very descriptive...

Indeed, let's look deeper

A high level python framework for web development.

That's better, we can dig into this now

Django is a Python framework that is built and maintained by experienced developers - it was first released in 2005 and is a widely used technology in the web development space. It is 'high level' which means that Django already contains a bunch of code necessary for you to create fast and secure web applications rather than having to type it yourself.

Sounds like cheating...

Call it cheating, call it a framework, call it a library if you like - it's saving you precious time and means that you won't forget stuff. Do you want to manually set up admin and all the fiddly database management by yourself? Do you?

This is why frameworks were made. They ‘start you off’ quickly, so you can get on with all of the fun parts of your project. Django just happens to be a framework for the Python language.

So why do people choose Django over all of the other frameworks out there?

Great question.
Django is built in a way that enables you to build secure and maintainable websites quickly. It includes everything that you might need ‘out of the box’. This means that you shouldn’t need to install a bunch of other things to get your project up and running. This ‘out of the box’ concept is sometimes called the ‘Batteries included’ philosophy.

Cool, can I use it? 🤑

Django is entirely free, and it is also Open Source; this means that if you have a suggestion or change to the framework that you think many people would also find useful, you can submit your request or even make the change yourself and make a pull request! Thanks to the philosophy of having everything working together in this framework, everything works seamlessly and follows consistent design principles. This is important because you shouldn’t have to fuss around with any part of the configuration; it is all set up for you. Django includes access to some popular databases and provides you with a secure way to manage accounts and passwords. Again, this functionality is ‘out of the box’ (Batteries included!) Of course, this functionality will have been tested fully and means that you’ll avoid any common security mistakes such as putting session information (cookie data) in a public place or forgetting to hash (scramble up and distort) passwords.

Smart and security-conscious!

Yes, and that’s not all - Django provides built-in protection from vulnerabilities such as SQL injection, cross-site scripting and…

What?!

Hmm, yes… ok let’s do a quick breakdown of that:

SQL injection = someone attempting to gain access to data in the backend by typing in SQL (a backend database language) into a web application to try and trick the application into running the SQL and giving the user data that they shouldn’t have access to.
Example:
HackerPerson types select * from secretInfo into a text field on a frontend form.
person in hoodie on computer in dark room
Note: It’s really great that Django includes this as standard for you to use out of the box, however it is pretty standard for websites to protect against SQL injection - it’s a pretty ancient and well known method of data harvesting…

If you want to learn more about web security, this site is pretty good.

What if I want to build a huge and successful web application?! I have plans for the next Youtube!

Funny you should say that...

Youtube is built with Django! This isn’t surprising; actually many of the sites you and I use every day are built with Django - after all it is fast, flexible, security conscious and many other things.
Back to your point - you are asking if Django is a scalable framework, i.e. can it adapt and grow with the application you build?
Yes, Django is scalable - in fact it is built using the ‘shared-nothing’ architecture principles. This just means that all the little parts and components that go into the framework are replaceable and changeable.

Like Jenga?

Colourful jenga bricks
I guess! Jenga/Django, try and say that fast…!

Back to the topic at hand - scalability. Django copes with your site recieving extra traffic (visitors) by being flexible and allowing you to add extra hardware (caching servers, database servers, or application servers) anywhere you need. One of Django’s most successfully scaled users is probably Instagram.

DRY

This buzzword/acronym pops up everywhere, and yes Django also uses DRY priciples. DRY just stands for “Don’t Repeat Yourself” and just means that you shouldn’t write duplicate code, or code that does the same thing. Django will help you implement this principle into your application, however it is pretty common and you should be trying to do it anyway.

Ok, DRY lecture over…

In reading the Django documentation (which is pretty good by the way), it seems that Django does, in fact, let you use components. This is something I’m familiar with from Vue (a JavaScript framework) and means that you can create reusable files, almost like code snips that you can call into your application:

Example:

I want to create a portfolio with 5 pages. I want a navbar on every page. What should I do? My options are; write the code for a navbar on every page (this might take a while and will be tedious) or I could write the code once and copy/paste it… (this comes with a VERY HIGH chance of errors and bugs.
In comes our saviour, Components. Components mean that you can write your navbar in a file called navbar.vue......wait……navbar.py... and then call it into every other page you need just by typing import navbar or something similar…

Ok, I got carried away with that analogy because I got excited to be writing about something I actually recognised, but let’s get back to Django.

Are there any cons of using Django?

As someone who has not played with Python or Django myself - these opinions are not my own:

It’s not the fastest
If your website isn’t properly optimised for speed, you may not get the best results when you are using Django. However, the framework does offer some built-in optimisation test to help you if you think this is a problem you may face.

Lack of convention
Compared to a framework such as Ruby on Rails, everything in Django has to be explicitly defined which takes time. However, Python is generally a language where you should explicitly define everything anyway, so if you are using Django then we can maybe assume that you wouldn’t find this a problem…

It isn’t great for smaller projects
As Django was built to help you build larger CRUD (Create, Read, Update, Delete) applications, it will probably be overkill on your small one page project, so make sure that you are using the appropriate tool for your project and don’t just go with the one that sounds the coolest (Django does sound pretty cool)

Confusing for search engines
It’s true, searching on google for ‘Django’ may leave you confused as there is a film by that name. I recommend searching for “Django framework” to make sure you get the most relevant results.
Django Unchained is a really great and important film and you should watch it.
It is not about tech frameworks

Happy Django-ing!

💖 💪 🙅 🚩
javascriptcoff1
JavaScript➕Coffee🚀

Posted on August 10, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related