Django is the largest and most popular Python web framework used all around the world by over 5 thousand websites. Its story began in 2003 when two developers, Adrian Holovaty and Simon Willison from Lawrence Journal-World, decided to leave PHP language and use Python instead. Django was released to open source under BSD licence in 2005 and since then has been developed by an international team of volunteers. One of the curiosities of Django is that its name was inspired by one of the best jazz guitarists, Django Reinhardt.
Django has become really popular, counting giants like Disqus, Instagram, Pinterest, Mozilla, Bitbucket, NASA, The Washington Post and Eventbrite among its users. Why has Django stolen the hearts of so many developers? Primarily because it’s well-tested and written according to the DRY rule.
Read on to find out more about Django and learn how to take your first steps in the framework.
Since Django is the most popular Python framework, there’s a lot of content written about it. Here are a few things every beginners should know.
1. Django is an “MTV” framework
If you look at the Django Book, you’ll learn that Django follows the MVC pattern closely enough to be called an MVC framework. The model layers are close enough for that. But there’s also a difference in view-controller and template-view, where Django’s view is more like the controller in MVC, and the view from MVC looks more like a template in Django.
In Django, the view is a callback function for a particular URL, so to understand the difference better, let’s say that in MVC, the user uses the controller to perform manipulations on data and the view prepares data coming from the model for output. In MTV, on the other hand, the user uses the view to perform manipulations on data and the view also prepares data coming from the model – but it also passes them to a template that is rendered and emitted as a response. Finally, we can say the controller in Django is hidden from view or better – the entire Django is a controller.
2. Has good performance and is scalable
According to sources from Djangoproject.com, Django can handle traffic of over 50 thousand hits per second which makes it an excellent choose for websites with many users and solutions requiring frequent server inquiries. Moreover, Django uses a ‘shared-nothing’ architecture. That means we can add as many pieces of hardware as we need.
3. Automatically generated Admin Panel
One of the top advantages of Django is the automatically generated Admin Panel. The admin panel is generated on the basis of Django’s ORM and offers developers functionalities such as user management, group and individual user permissions management, and data management options from our database. It’s also great if you want to develop custom futures and can be used like a CMS. However, it’s worth pointing out that Django is not only good for CMS apps: the Admin Panel is only one of modules and still Django is great pick for building non-CMS systems.
4. Support of many database and cache engines
Django offers support for many database engines like PostgreSQL, MySQL, SQLite or Oracle. Most developers recommend using PostgreSQL but that’s probably because they’re PostgreSQL fans. I think MySQL works just as well. Django doesn’t officially support NoSQL databases. But since the Django community is large and enthusiastic, there are a couple of open-source solutions like Django non-rel. Django also supports cache engines like Memcached, PyLibMC, Database, File Based, Local Memory (LocMem) and Fake cache for development (Dummy).
5. Contains its own template language
Django has its own template system, but there are no contraindications to using the template language you prefer like Jinja2 or Mako. The authors of Django say: “We happen to think our template engine is the best thing since chunky bacon, but we recognize that choosing a template language runs close to religion. There’s nothing about Django that requires using the template language, so if you’re attached to Jinja2, Mako, or whatever, feel free to use those”.
6. Contains its own famous database abstraction layer
Django’s ORM is one of the best database abstraction layers I’ve ever seen! There’s a lot of content out there about how to use it or how to adapt our existing database to be used in Django during migration. For Django 1.6 and above, there exists an available built-in migrations module. But for oldest versions, we can use also famous module South. Although Django doesn’t officially support databases like MongoDB, you can find an open-source library called Django MongoDB Engine provided by django-nonrel. However, keep in mind that Django’s Admin Panel is closely related to Django’s ORM so if you decide to leave the built-in ORM, the Admin Panel isn’t going to be available anymore!
How to get started with Django
The best way to start with Django is to follow the story published on the official Django website. Have a look at the introduction “Write your first Django app” with two advanced tutorials “How to write reusable apps” and “Writing your first patch for Django”. For more advanced developers, we recommend these Django tutorials and books.
- If you don’t have any experience in Python, be sure to read this: 12 best Python tutorials for beginners
That’s a great way for beginners to get started with Django and more experienced developers to return to it if they had a long break with this framework.
During the introduction learners create a public site that allows viewing polls and voting in them, together with an administrative interface where the use can add, change and delete polls. You can learn how to start a Django project and create a new app, manage and customize the Admin Panel, build and migrate database, use the built-in template system, write tests and manage routes.
Where to get help when you’re stuck
Before reaching out for help from more experienced developers, it’s a good idea to turn to Google. The fact that Django’s community is so large means that you’re probably not the only person out there experiencing the problem.
However, if you really need someone’s help, you can use Django’s mailing list or post a question on StackOverflow. If you’re planning to post on StackOverflow, it’s worth checking whether someone has already asked a similar question. StackOverflow members tend to be quite sensitive about duplicates.
Another great idea is joining the #django irc channel on freenode and ask your question there. But before you do that, learn more about the channel’s rules. Ask your question and wait for a reply. Your question should be concise and specific – it’s best to frame it in a single sentence. Avoid spamming the channel and never write private messages unless someone writes to you first. Be kind. 🙂 You’re the one seeking help but nobody is obliged to help you right away.
I hope this guide to Django makes you even more enthusiastic about taking the first steps with this amazing framework. If you have any questions, feel free to add them in the comments section and I’ll do my best to respond to you.