Leveraging the power of Django REST Framework's renderers with HTMX.
2023-07-21 , Terrace 2B

HTMX has been quite popular lately in the Django circles and has demonstrated how powerful it can be with vanilla Django. But... have you thought about HTMX paired with Django REST Framework and more specifically paired with DRF's flexible renderer system?


Django is most known for its admin. Ironically it is also one of the less Django-like parts of Django and one with many dimensions that make it harder to extend and fully customize. That's probably why, for several years, people have been trying to find alternatives to Django admin, packages that have had variables amounts of success like Django Grappelli, Django Admin2 or Django Admin Bootstrap.

One of these attempts is actually part of a very popular Django package, it's the Admin Renderer from Django REST Framework. Although it is quite powerful, I'm not sure it really ever caught on in the Django community.

But the Admin renderer is not the only renderer packaged with DRF, most of us are likely familiar with the Browsable API renderer and some of us have probably heard of the Template HTML renderer.

Before diving into the renderer itself, we will do a quick round-up of the capabilities DRF offers, both out-of-the box and also with a few extra addons and compare that to what Django Admin offers.

Finally we will look at the mechanics of DRF renderers and how, coupled with HTMX, the Template HTML renderer can bring dynamicity to an admin-like, feature-rich, CRUD interface born of Django REST Framework.

It will be up to you to decide... Is Django REST Framework going to be the basis of the admin of your next Django project???


Expected audience expertise:

advanced

Long-time pythonista, Django fan, co-maintainer and co-author of DRF-Schema-Adapter and other OSS libraries

I am from Belgium and have been involved in open-source at different levels for about 20 years.

One of the things I enjoy the most is sharing knowledge with others. And this is why I enjoy writing tutorials as well as giving talks and workshops.

Github: https://github.com/nanuxbe
Gitlab: https://gitlab.levitnet.be/levit - https://gitlab.levitnet.be/emma