Is there a resource which explains Django's internals at somewhat intermediate level?

The Django docs are a great resource and preetty much always understandable even for a beginner like myself. However, certain design decisions/way things work are a complete mystery to me. For one, I dont get why the fields for a model are defined as class variables and when we pass arguments to create records, how they get mapped to those class variable fields. Also, how can the url mapping work from the project urls.py to an application urls.py without adding the created app to the installed apps list? I get that this isnt strictly relevant to building stuff, but it leaves me feeling unsatisfied. Ideally, I’d like a resource which helps me build a mental model for the framework. Does anyone know of such a talk/article/other resource ?

I’m not aware of one definitive source - besides the source itself.

<opinion>
I would say that the first step is to make sure you really understand Python. Django takes advantage of pretty much every feature of the language, with a heavy usage of metaclasses - using classes to make classes.

Once you understand Python metaclasses, I think you’ll find Django’s source relatively easy to read and understand. (Except for the ORM itself. Personally, I still find it to be somewhat “impenetrable” to my mind, not that I’ve spend a whole lot of time trying to study it.)

Given the rate of change and evolution of Django, I think that’s the only way you’re really going to be able to ensure that what you’re learning is current and accurate.

However, going with the full current version and all the features that have been added over the past 15ish years might be a bit much to digest. It may be an interesting exercise to pull one of the very old versions and start reading through that. It’s going to be a lot smaller code base, and perhaps with fewer features and options, easier to understand how things have developed over time.
</opinion>

Beyond that, in trying to find some resources for you, I stumbled across the recording of James Bennett’s “Django in depth” talk from Pycon 2015.

I’ve not yet watched it, but it’s now on my to-do list. (James is an absolutely fantastic teacher of this kind of stuff. I had the great fortune of being able to attend a tutorial of his a couple years ago at DjangoCon, and that was three hours that were very well invested.) I also found one of his blog posts you may find interesting.

Also, Carlton Gibson’s talk from DjangoCon 2019 is quite educational in understanding the full request-response cycle. (Note: This is not a “how you want to do things” video - IMO, he’s just pushing the boundaries as a means of providing information as to what’s really happening under the hood.)

I’ve had the great fortune of seeing Andrew Godwin speak at DjangoCon a couple of times. His talks on Async go into great detail about the issues involved in adding async support to Django - if that’s of any interest to you, I suggest you find any of those videos. Also, I remember a talk he gave a number of years ago about “migrations” - also excellent.

Finally, a few years ago there were conferences named “Django under the hood”. There are a number of youtube videos in a channel by that name. I’m guessing (not having watched any of them) they’re all worth watching, depending upon your interest in the topic being presented.

1 Like