Elm framework for Django

Hi team,

I created a thing:

My work recently moved to Django from an Node + Elm SPA combo. We are using data science pipelines pretty heavily and python just has all the heavy hitters, so it made sense to use.

It has been a fantastic experience using Django, the admin feature in particular is incredible, and all the conventions and tooling is refreshingly solid.

We had a huge amount of Elm code we built for the SPA and definitely wanted to salvage as much as possible, but we were nervous that we would need to write a bunch of flaky code to get it to play nice with Django.

We have gone all in on Django server rendered templates, so we needed a way for us to write Elm programs, declare them in django templates and have them hydrate on the client.

We also wanted all the decoders and Elm models to be generated from python flag declarations which double as server side validators for Django data that is being passed to the given Elm program.

We were considering other frameworks but I was given a week to build a proof of concept for Elm before we seriously considered anything else. Safe to say I was motivated!

So I created djelm!

It’s still pretty young but well beyond the first version I built.

How we are using it
All static UI is server rendered and for anything dynamic we either use htmx or Elm.

It’s pretty remarkable how far you can get with htmx, but some types of dynamic UI just doesn’t perform well with constant round trips to the server, so Elm handles that for us.

Because Elm programs are declared on the server rendered template we even use htmx to render html that includes Elm program tags which then just hydrate on the page.

Django form helpers also allow you to write your own templates for form field widgets, so we can easily include Elm packages like Confidenceman02/elm-select for select and multi-select fields and they just show up as you would expect.

All in all it has been great fun to build, and there are so many ways it can work with Django that I will be exploring. I’m also pretty excited to share it with the Django community, we might be able to recruit some folks who want to give Elm a shot in an environment they are comfortable and familiar with.

Thanks for reading!

23 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.