The Django Framework: A Beginners Guide
Diving into a new development language can be scary to say the least, especially if you’re moving from front end to backend, or simply a newbie. Save yourself months of procrastination and decide today whether or not to take the big leap and start your Django journey!
What is Django?
Django is a Python based web framework
Django is a server side framework, also known as a backend framework
We use python to build websites and python itself is one of the top programming languages, Django is one of the top frameworks for python
Django is a heavyweight framework and has a batteries included approach meaning it is more specific and strict in how you build your application, that’s not a bad thing, with this you get more packages, libraries and modules and you follow a good design structure
Flask (another backend framework) is a lightweight framework so you’re installing a lot of packages yourself, if you’re a beginner you may not follow the best design structure
Django forces you to do things a certain way which is a great for newcomers and you can still customise it
You can bend Django to your own will in how you want it structured
Django is comparable to ruby on rails framework, with php and laravel it’s more like laravel, whereas flask is more like express for node.js
MVT design pattern - model view template see below
What is a web framework?
A web framework is a collection of modules, packages and libraries designed to speed up development
When using a web framework, you don’t need python code to do absolutely everything
It pre configures a lot for you and is designed for one specific purpose and in this case for building websites
What can you build with Django?
With Django you can build, for example, a social network, an e-commerce website or an API mobile app. It is worth noting that Django can’t actually build a mobile app for you, you can use part of Django to build one though
Some companies that use Django and can therefore validate its power include: Spotify, Instagram, Pinterest, YouTube, Udemy and Dropbox. This should validate whether Django is the right choice for you and if it can do what you desire
Django is not always the best option but it can do pretty much anything
Building APIs with Django
A lot of coders decide to learn Django for the sole reason of building APIs, that’s totally fine if you want to build a mobile app or use some kind of front end framework you need some api data, Django makes this easy
Django rest framework exists and is built on top of Django, this framework helps you build rest APIs or just APIs
The MVT
The Model View Template is a model structure/design pattern
Django follows the MVT structure
The only difference here between the mvt and mvc (you’ve probably heard of this in relation to other frameworks, Model View Controller) is that Django takes care of the controller aspect
For those of you that are completely new, MVT represents the following:
Model - data access layer - that’s your database, how we model data, this is gonna be your database tables, built out in classes
Templates - presentation layer - this is what the user sees, so it’s gonna be the webpage
View - business logic - so for example we have the Codú website, when someone goes to that website they’re gonna be going through some URLs, we’re gonna find a url that matches some kind of function in the backend and that’s gonna be our views
The views in the view layer are gonna go ahead and get some data probably from the models and it’s gonna render some kind of template to us, we send that back to the user so that’s the flow - we’re requesting data, the views a business logic and we just get this and send it back to the user so that’s the mvt design pattern
Django documentation
The documentation itself could be intimidating but once you have a question on how something works reference the documentation, it will really help
Other python frameworks for research purposes
Flask
Cherry Pie
Web2py
Pyramid