Oh, I Found a Security Issue
Published October 26, 2026
This video features Christophe Henry at DjangoCon Europe 2026 in Athens, Greece.
TALK: Django templates on the frontend? by Christophe Henry
In recent years, the Python community has widely adopted HTMX and Hotwire's Turbo. The paradigm of these frameworks is to use AJAX requests to handle changes in the web page. However, there are situations where each HTTP request has a cost, either in bandwidth, volume quota, or any other form of resource cost. In such situations, your application cannot afford to make an HTTP request every time a subform is added to a Django Formset, for instance. After encountering this situation several times, I decided to start working on django-template-transpiler, a tool written in Rust that converts Django templates into a JS function that renders the DTL on client side, similar to what Handlebars can do. The rationale to allow the developers to make your page dynamic, while minimizing the number of HTTP queries and render both on server-side and client-side using your Django templates as a single source of truth.
More information: https://2026.djangocon.eu/speakers/FC3WLA/
Follow DjangoCon Europe on social media:
*X - https://x.com/DjangoConEurope/
*LinkedIn - https://www.linkedin.com/company/djangocon-europe/
*Mastodon - https://fosstodon.org/@djangoconeurope
#django #djangocon #djangoconeurope #djangoconeurope2026
Automatically transcribed, so expect mistakes in names and technical terms.
Speaker 1: That looks good, doesn't it? So uh okay enough of that stretching now please. Um Let me welcome Christophe Henri. He's a long-year contractor, twelve years I've understood, for the French government. So um You take us away from Django, far far away into another country world, which is called the front end, right? Please give him a warm welcome too.
Speaker 2: Thank you. So first quick correction. I've been a developer for twelve years but independent contractor for the French government for the past six years. And those are my socials. I am Christoph Henry on GitHub and as I am quite a boring person I am also Christophe Henry on mastodon. sop And today I want to recount the story of how I ended up working on Django template transpirer. And it all started with formsets You see, form sets in Django are designed to be used in a very specific way. You render a number of uh empty or field
Speaker 2: forms. And then you have a button to add any number of new empty forms. But let's say your designer is uh feeling fancy and they decide that the empty form is gonna go in a dialogue. And when validated, it's gonna render a Card with uh hard-coded uh information. In this situation you have two options: either you just drop it and you decide to use a JavaScript template framework like uh Vue. js or React and that all bring the that that all brings the use of Node.
Speaker 2: js which is in my opinion never a good idea Or you take the road that the general community has been taking more and more in the past years, and that is you use HTMX or a hotwired tub. But that comes with a problem because uh then each time you want to change uh some part of your UI you need to issue an HTTP request. And let's say you operate in a uh part of the world where um it's not always convenient to issue an HTTP request each time you want to change part of your UI like
Speaker 2: For instance, you you may have users that have some kind of resource cost each time you issue a request. For instance, they have a low bandwidth or they have data limits or simply they just pay to the megabytes of data consumption In this situation the solution should be would be something like handlebars, but it compiles your Django templates. and you can use it on the front end and that's why and I ended up doing. And I started when I stumbled upon um a project which is called Django Rusty Templites. Uh
Speaker 2: this is a currently ongoing develop um there is a this is um a project that is uh current currently uh in development and it's an implementation of the Django template engine in Rust and it has a Django template parser which I could reuse. And I decided to pair it with uh another uh another project which is OXC and it's another Rust library uh which can generate pass uh JavaScript and I could use it to I could use the both to pass the Django template and then then generate a JavaScript function to render it on the front end
Speaker 2: So what does it look like? Um this is a really simple and kind of stupid example. This is a simple uh Django template and on the right you have uh the generated JavaScript function. It's really simple, it generates a single JavaScript function that you can call to render. uh some part of your U some uh parts of your UI. Uh it takes two are two sorry two arguments Uh the second one is context, uh which will be familiar to every one of you, I suppose. The first one is engine that is because uh a part of uh part of the library is pure javascript.
Speaker 2: Um the rest is just just aggregating the the all the parts of the templates and just string concatenating to the resulting to the resulting HTML. So what are the use cases for this? Um as I say, form sets. but also alerts or models. Really any kind of situation where a user interaction would change significant parts of your UI and you don't want to issue an HTTP request for that. So what is the current state of this project?
Speaker 2: First, it's very rough, so please don't use it in production. There are a few things that are in yet, uh for instance the the if and else tags, the full and empty tags, a few filters like add, add slashes, cupfest, center, get default default if known and divisible but uh sorry divisible by and lower and now we have to discuss what's not in yet and what's not in uh first is clean card. There is panics and unwrap everywhere so currently the thing uh risks of exploding to your head
Speaker 2: quite any moment Most of every other tags are not in, for instance, uh uh in particular include an extend. expect those to be quite difficult to uh implement. I have not um find um correct arctic architecture now to implement them partial dev should pose a similar problem Translation and URLs, I expect them to require a specific API to allow them to discuss with the Django framework. And there is also
Speaker 2: error management during render. So panic and unwrap are during a transpilation, and there is also everything that risks of happening during rendering. This is an example where we try to unwrap three elements. But within the context we just uh passed a list of pairs and that's a problem. Uh I don't know yet how I should handle that. Should I throw a JavaScript error? Should I um log something in the console? I don't know yet. And there is escaping. So escaping currently is technically in.
Speaker 2: I would not assert that it is safe. I am unsure I did that properly. And there is also all the differences between JavaScript and Python APIs, for instance, dictionaries and mappings. using dot items on a diction on a Python dictionary is quite a common pattern in templates. Um the function name is different uh in JavaScript. It's entries, I think. So I don't know yet how to solve that. That would be a uh an issue for later time. All right, do we have time for a quick demo?
Speaker 2: Will I succeed in doing a quick demo? This is an incredibly cursed thing to do. Please stop trying to do demo on live stage. Oh right, my PyCharm is opening on the wrong screen. That will allow me to show you the code. If I get the mouse. Okay, so I was as I was saying earlier, uh there is uh some parts of the code uh that are that is implemented in pure JavaScript. In particular, the filters are just here. So this is a JavaScript file that is embedded in the
Speaker 2: In the Rust library. Here you can see the implemented filters. As filters in Django all have the same grammar, it's very easy to implement them in pure JavaScript. So filters are all pure JavaScript. If you're looking to contribute to the project, filters might be a good entry point. Tags are another beast entirely because they some of them require specific parsing. uh so it's a bit it's a bit more difficult. They that tags would require writing uh specific uh Rust code All right, let's launch
Speaker 2: what So this is my demonstration app. It's currently an empty page with a button to add a form This is the kind of situation I talked about. Your designer put um empty form in a dialogue. This is very, very beautiful, but incredibly cost to implement in JavaScript. In uh in Django. Um let's add a name. Can someone submit me a name?
Speaker 2: Oh, Christoph. Uh what's the age? What's my age? Thirty-six And let's say I am non-binary. This agenda, uh I call it this to be required only when you put other Uh there is no real constraint here. So it would work if I put other here, but it's empty here. It's just a demonstration. Let's me save that. Oh, sorry. I should probably open The console to show you that there is no network request ongoing. So this is a new form. Let
Speaker 2: me add Rudy. I don't know. Uh Rudy is fifty-five, and there are other gender. Well they are a notch user for instance. Let me save the change. Okay. So this is the kind of situation where you would be a little bit constraint, little bit constrained the designer uh decided that when the user puts another gender and fills the other gender field uh with something uh the other gender field should be rendered between parenthesis
Speaker 2: and as you can see I added a form and no request happened here. Uh so if you believe me everything is rendered on uh on the front end. I can show you the code for that A five. Yeah. So um This is the template. Uh the template is really, really simple. And as I say, the code is very very rough. So all the template complation is currently happening in the app config.
Speaker 2: Uh this is because currently there is no uh Django package for that. This is pure Python, so I have to call everything manually. Um The only public API is just transpile. It takes a string, it takes your templates and your template uh other string. and it spits out uh the JavaScript uh code as a string too. So everything I'm doing here is just um ensuring that the the correct uh directory is exists and then I um just open the template here to read it. I open the um
Speaker 2: a target uh JavaScript file, I transpile the code and I write the file back. This is all happening uh when the when the Django application is booting. and everything ends up here. This is the resulting JavaScript uh JavaScript code. probably recognize the export the field function with the two arguments engine and context and the rest is just string concaten concatenation. with a few uh calls to engine uh methods to get the context variables, uh get the correct tags, uh get the correct filters, etc.
Speaker 2: That was my demo. Um thank you. The demo went well in my uh to my great um happiness. Alright, I'm done. If there are some questions, I will be very happy to answer them.
Speaker 1: I'm sure that questions, yeah.
Speaker 3: Thank you, Christophe. That was really interesting.
Speaker 2: Thank you.
Speaker 3: I see many opportunities for tasty information to leak through the context. into the browser or am I misreading something. Is that
Speaker 2: sorry, come again?
Speaker 3: Opportunities for information for data on objects to leak into the browser because now it's all being
Speaker 2: a little bit of a uh yeah but it it's uh it's designed to be used in situation where there are user interactions. So the user is already giving this those information within the browser anyway. But yeah that may be an issue. Please don't use that for uh the for sensitive information Yeah, it's not it's not designed to be used in situation where you already have the information for instance in the database and you transmit them to the browser to be rendered. That would be something like Vue. js or React. This is really designed in situation where you have uh a part of your UI that could be rendered on the back end because you already have the the data
Speaker 2: or on the front end because the user is currently giving them
Speaker 3: Thank you.
Speaker 2: Thank you. Oh, yeah. Yeah to to um to precise a bit the my answer um this is to be used in situation where uh you want to use your Django template as a single source of rendering. So you could use it you could use it on the back end and you could be in a situation when where you have to use it on the front end. Uh thank you. Where where is uh yeah.
Speaker 4: Could you elaborate on your decisions comparing the approach that you just presented with pre-rendering those models and whatever you have in there with
Speaker 2: Well as I said you are in a situation where you don't have the information yet. This is a user interaction. The user is going to give you the data, uh like for instance they are filling a formula. or uh they 're I don't know, clicking a button, uh they're um ordering something on the shop. Like this is the kind of situation. So either you have the situation the the the the data on your database and you use the back-end rendering or you are currently interacting with the user and your UI is going to change based on the user interaction. This is the kind of situation where is uh
Speaker 2: it is uh um um where it is uh uh thought to be used. Okay, another question? Yeah, yeah. Where is it? Okay. Hello.
Speaker 5: Hello. Thank you for this.
Speaker 2: Thank you.
Speaker 5: tool is that you need to have uh uh the compilation step run before deployment. Am I getting that right?
Speaker 2: Yeah. Yes. Uh yes, um really this is this is really like handlebars but for Django templates. So uh if you've if you view uh sorry if you have used it uh handlebars You have an option to transpile your templates beforehand in a JavaScript code to be using the front end and this is very much like this. So uh here in this situation in the demonstration, uh it happens only once. It happens during the uh the server boot-up uh it could happen on the fly. Uh it's just I design uh I just coded it like this, but it could happen
Speaker 2: uh like for instance you you you're requesting uh the the javascript file and it's not ready where yet you just transpile it on the fly it could happen then uh it's just sky is the limit
Speaker 6: In in HTML there is the uh the template tag uh to just regenerate some part of the of the page of the DOM Uh just reinject it. Why didn't you use that?
Speaker 2: Uh well because I didn't know it. Oh yeah. Well yeah no template is just it's it it's basically a div with uh some uh some specific API but it's not doing time plating. It's not for instance it's not rendering variables. If you want to render something you need to manipulate the notes yourself like for instance you select the node and you put an inner inner text this is uh this is making this is uh generating a lot of bullet boilerplate javascript and you don't have logic Like for instance, you don't have four loops, you don't have conditionals.
Speaker 2: Uh really uh templates is uh great, but it doesn't define a template language It's really just uh a div with a few specific APIs. I think there is an ongoing effort to define a templating language within a HTML but I don't see it landing within several years. Hey. Hello. Hey Chris. This
Speaker 7: this looks almost like the Holy Grail in a way.
Speaker 2: Sorry, I did I didn't get you?
Speaker 7: It looks almost like the Holy Grail. Okay. To be able to reuse my Django templates on the front end. I'm trying to think about the um limitations you mentioned.
Speaker 2: Yeah.
Speaker 7: Um so you mentioned include exclude uh includes, extends, and partial I can live without that. Oh sh are there any other like what do we need? We need loops, we need conditionals and are there any other major tags that you think actually
Speaker 2: Okay, the uh beyond uh beyond uh the controls uh like uh conditioners and for loops uh what i needed the most in the past is really urls. There I I am aware of several projects uh to expose uh Django URLs uh to the front end. Uh most of them were maintained for a few years and are now deprec uh are now unmaintained So this is a shame. The ability to have iComplete template system, a Django template system on the front end and that allows to use also the uh the URLs would be really great.
Speaker 2: Uh what else would be great? Yeah Maybe m maybe uh maybe other users will find uh y cool use cases, but uh yeah Well I believe we still have time for uh a few questions.
Speaker 1: We do.
Speaker 2: Or is it um are we done I think we're done.
Speaker 1: Okay. Thank you so much.
Speaker 2: Thank you.
Speaker 1: Take handed applause.
Speaker 2: Can I request we light the the audience so that I can take a selfie? This is my uh fifty minute of frame.
Speaker 1: Yeah, so you you you need lights back. Yes, please.
Speaker 2: Are you okay with it?
Speaker 1: Yeah. Uh can anyone ask?
Speaker 2: Yeah, can I have uh some lights on the audience?
Speaker 1: In the audience? I don't know how to do that.
Speaker 2: Seems I can't have lights on the audience.
Speaker 1: It's coming. Ah
Speaker 2: nice.
Speaker 1: So you have a big hand.
Speaker 2: Thank you, thank you all. Thank you.
April 15 - 17, 2026
Athens, Greece
Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026
Published October 26, 2026