17
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?
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.
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.
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.
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.
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.
Yes, and thatâs not all - Django provides built-in protection from vulnerabilities such as SQL injection, cross-site scripting andâŠ
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.
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.
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.
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.
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.
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.
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!
17