Rewriting Django from (almost) scratch in 2021
2021-06-04, 10:00–10:45, Main Room

You're probably asking yourself "Why would someone wanna do that?". Django is one of the most successful web frameworks out there, the codebase is well established and well tested.

That is true. On the other hand, a codebase that old is bond to have some technical debt.
IMHO, Django's technical debt is mostly situated in the admin which is one of the most appreciated features of Django while at the same time, possessing the least people familiar with its internals or willing to learn them.
Another sort of technical debt is one that is backward compatibility and having to keep choices made more than a decade ago.


One of the decisions that was made 15 years ago was to use home-made code for everything. Django depends on very few libraries. Django doesn't use anything from the Python eco-system, when it comes to ORM, templates, routing, etc.

And that is a decision I would probably have done at the time as well. The Python world was much less welcoming at the time and documentation was still regarded as a second-class citizen. Let's not even mention the wrath you were taking the risk of exposing yourself to if you dared make a pull request on a project you weren't involved with.

Those choices are not the only reasons to consider a rewrite though... After attending several Django conferences, I noticed a few trends about what prominent Django developers would like to change. For example WSGI middlewares is something that's often put on the table, websockets is another of those things that comes up very often.

It is true that the world of the web is quite different today compared to what it was 15 years ago. It seems to me that today REST API's and websockets are first class citizens while server-rendered pages have become less important. Once again, that's just a personal feeling.

A complete Django rewrite is also not my very own idea, several people have been working on a similar idea. Tom Christie has been working on many libraries in order to be able to rewrite Django as an async framework in order to better accommodate websockets. Others like Tobias have been working on something similar but starting at the other end of the problem. I guess this is just my own version of that thought experiment.

For this thought experiment I will care about retaining the "spirit" of Django as I perceive it but I will not care at all about backward compatibility!

What does a Django rewrite needs to achieve in 2021?

  • Batteries included: Anything that claims to be a Django-like needs to come with everything out of the box
  • A friendly ORM with a syntax that is closer to the objects than to SQL
  • Middlewares
  • Sessions
  • Authentication and authorization
  • Routing
  • Easy to build REST API's
  • Websockets
  • Template-based rendering
  • Static files serving during development
  • Easy documenting of API's
  • MVC implementation
  • Easy to use CRUD controller and associated views
  • A powerful admin(based on its own CRUD controllers)
  • Error management

This talk will cover all of those points, how they could be approached and whether using an existing Python library for that job might be a good idea

Code:
- Cordy
- CookieCutter for starting a project
- Demo app (Splendid)

Demo: https://levit.be/uploads/Kazam_screencast_00003.mp4

Slides: https://slides.com/emma_be/cordy

Video: https://www.youtube.com/watch?v=yaWGZnyzZqI&ab_channel=DjangoConEurope