Learning Django: What Makes it Hard?
What makes the Django web framework hard to learn?
I’ve given this question a lot of thought recently. As the author of Django for Beginners, I receive regular feedback from readers– both total beginners and those experienced in other programming languages but new to Django–who are struggling. I’m very empathetic since I first learned web development back in 2013 with Django and it was not a smooth road at all.
Why would someone even consider a framework like Ruby on Rails which entails learning a totally new programming language that has little usage outside web development?
Here are Django’s positives in my opinion:
- written in Python
- stable and mature, regularly updated
- very well documented
- proven at scale (Instagram, Disqus, EventBrite, etc)
- Django Rest Framework makes building web APIs easy
- robust 3rd party ecosystem
And here are some possible reasons why Django is challenging to learn:
No 1: Lack of beginner-friendly tutorials
Why isn’t there a comprehensive resource like the Rails Tutorial available? One that baby-steps through building a simple CRUD application with user accounts and deployment? If it exists, I’m unaware of it.
Is it because the average Python programmer is more experienced? Or assumed to be? I genuinely don’t know why.
No 2: Relatively complicated “Hello, World”
Compared with Flask or Express, creating a simple “Hello, World” takes more work in Django. You need to correctly install Python 3, virtual environments, create a new Django project, a new app, and then install urls at both the project and app level, plus create a view in the app. It’s a lot.
If you’re an experienced Django developer, yes, you don’t have to create an app for a “Hello, World” example, but since the project/app paradigm is used throughout Django it’s less confusing to beginners to just start with this approach.
No 3: Local development setup
Django (and most other frameworks) by contrast can be difficult for a beginner to setup. You must install Python 3. Then install and configure virtual environments. Then install Django. And really you should also download and configure a local database like Postgres rather than the built-in SQLite. It’s a lot.
No 4: Multiple ways to do the same thing
Django gives developers a lot of flexibility when it comes to structuring a new project. This is a double-edged sword: I speak from experience when I say it is deeply confusing to read multiple different approaches to basic project setup, let alone more complex cases.
As an example, consider the official polls tutorial which advocates including templates in an
app -> templates -> app -> template_name.html format, which is how the Django loader looks by default. That’s fine, but then most real-world projects advocate tweaking your
settings.py file and putting all your templates in one project-level templates folder. Or putting project-level templates there but including app-level templates in the app directories.
No 5: Function-based views vs Class-based views
Class-based views are in my opinion a big improvement in Django and seem to be the way things are headed. However…it’s really confusing to have tutorials switch between the two, yet this seems to be the normal way Django is presented (see the previous point on Multiple ways to do the same thing). As in, here’s the “real” way to do it with functions and here’s the CBV shortcut.
I understand why showing both approaches increases understanding once you’re at a given level. But I think focusing on how simple things can be with CBV is a better up-front approach. Use CBVs and even better Generic Class Based Views to show how little code we need to build common functionality. Then, once the reader has gotten it to work and has some confidence, go deeper with the function-based approach or show how to customize the CBVs. Most tutorials do this backwards.
No 6: The Urls, Views, Templates dance
It takes a lot of practice to become used to updating three separate files for a single new page on your site. It’s not always obvious where names or arguments in a URL map to a view, let alone how to properly display them in a template. In particular, once you start doing detail views, things get hairy for beginners in a hurry.
I’ll add to this post over time but for now these are my main thoughts. And to be clear, I’m writing this because I think Python and Django are fantastic and I want to figure out how to share that with more programmers.
Looking for a way to go from beginner to intermediate Django developer? Check out my book Django for Beginners.