Serving Files with Django
Published July 31, 2021
This video features Jochen Wersdörfer at DjangoCon Europe 2026 in Athens, Greece.
TALK: When SaaS Is Not Allowed: Shipping Django as a Desktop App by Jochen Wersdorfer
Some teams face constraints that make standard web deployment impossible: confidential data that must never leave user machines, air-gapped environments, and workloads that are too expensive to run centrally. This talk presents a production pattern for turning Django into a desktop application by packaging it inside Electron. The case study is Steel-IQ, an open-source steel-industry simulation tool for multi-decade decarbonization scenarios, shipped for local execution with sensitive data.
More information: https://2026.djangocon.eu/speakers/BWWWMK/
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: Hello. It is my very great pleasure to introduce Jochen to you, who will be talking to us about Django as a desktop app. Always exciting to hear an interesting new way of using Django. I've been told there's a workshop starting down uh downstairs as well um now if you're wanting to go to that um but over to Jochen.
Speaker 2: Hi Okay, hi. Yeah, uh I'm Jochen Wasslaffer. Um I uh do Django application development since about 2013. Uh I have a John Speaking Python podcast. Um And for my freelance work, I usually do half of the time juggle backend development and the other half I spend on data science and machine learning projects Yeah, and uh somehow this uh lately drifted into desktop development uh because I did this uh project wrapping Django in an Electron app last year and uh this year I also do a Qt desktop application using PySight.
Speaker 2: So At this point I I uh I fear that this might be uh a punishment for something I did in a past life or something. But uh yeah, so it is um okay Yeah, uh UIs. Um this talk is about what you can do when you can't run Django on a on a server. So in the end uh you should maybe be able to play around with a little demo app and uh also uh might get an idea on what to do if you have an existing application that you want to wrap in an desktop application. And yeah, maybe quick question. How many of you
Speaker 2: use electron apps on a daily basis Okay, so quite a lot. I think you already made your piece with your text editor taking up to two gigabytes of RAM. Very good. I think we are already already friends here. So uh yeah. Back to the project I did last year This is uh it's it's steel IQ, it's an open source modeling platform for steel decarbonization. You can use it to run simulations of how to decarbonize uh steel um so uh furnaces and uh it it contains um code for uh for for for plant economics for uh running trade flows uh and geospatial stuff like uh cost of energy and so on
Speaker 2: so on. It's a quite complex uh domain and um But it matters because uh the steel industry is responsible for about eight percent of all CO two emissions worldwide and uh knowing which policy changes would maybe bring that down could be important. So Yeah, interesting project. Um in the beginning we thought about what UI should we use, but uh the problem is that uh yeah uh we knew that we couldn't use a website because We knew that that our target audience has private, sensible uh proprietary data. They probably don't want to upload anywhere, but they will need it to run those simulations.
Speaker 2: And um so we thought maybe we just um distribute it as a Python package using PyPI or maybe write a command line interface or maybe provide some Jupyter notebooks uh showing how to run simulations. But yeah, our users are probably uh domain experts in the steel industry, uh sitting in front of uh Excel sheets uh using Windows desktop computers or worse. And uh yeah they they probably don't run Python at all and um they they need something they just can install and run. And we had previous experience with using Django for economic models and we were very happy with that. So we thought it would be really cool to
Speaker 2: if we if we could keep that. And then we had this wild idea of maybe we can just wrap the Django app in an electron shell and ship it as a desktop application to our users. And we thought, okay, we might try that for one or two weeks, and if it feels wrong, then we try something different. Um but uh surprisingly this was this was easier than expected. After one week we had some kind of working prototype and the the development didn't feel really like creating a desktop application but just doing normal Django web uh web development. You have your uh dev server and um you work on models and and and views and stuff like that
Speaker 2: And um yeah if you if you do development for a website then you also have some point where you deploy it to production side. And for us it was like more like deploying to a desktop application. Like different deployment target, but uh the the the develop development process otherwise stayed quite the same similar. So this was a very pleasant surprise so we kept using Django as a UI layer for our project and uh Yeah in uh November 2025 we shipped this as a finished product. It took about a year. Uh 15 people were working on that, maybe half of them writing code. Yeah, uh in the end it was about 100,000 lines of code, so it was not really small.
Speaker 2: It was kind of a decently sized project. And um yeah, we have real users using that to run simulations uh in the scene industry. And yeah, this kind of proves that you can do that. It's possible at least. And uh yeah, it uh The the problem is uh you you can't really use that repository, it's open source. You you can look at it but uh it's uh um it's not really uh good as a tutorial I think because it's just too big and there are lots of steel uh domain things in there and edge cases so uh I for for this talk I created a different repository called desktop Django
Speaker 2: starter, which is just a small demo shut application and all this things you need to do to make it work in an electron shell And that's has some additional advantages like more ponies, less steel. It uh it also ah the documentation is also written in uh with the use case in mind that you might want to wrap your own application in an electron shell. So this might also be useful. And uh okay, let's let's maybe have a look at the architecture of the demo app that's in there. Yeah, it's a pretty normal uh Jugo application. So you have a user uh looking at a UI and a browser window. uh providing input by clicking around and uh
Speaker 2: entering keystrokes and then you have the usual response uh uh request response cycle to your Django server And um yeah, just normal REST stuff. And the Django server then has its application state in the in in a database, uh SQLite in our case. And there's also a task queue for background workers. Oh, we heard this quite a few times today, also yesterday. And uh in the data layer there's also a file system containing images, fonts, huge upload user-uploaded Excel files. uh yeah and the only difference between a normal web application and um
Speaker 2: this desktop application is this small outer frame um called main. js. This is a script. If you double click the app icon then it gets started. It's a node. js script and it um starts all the other processes in the system. It's it's orchestrating the lifecycle of all those things in in the in the frame. So we let's have a look at the uh lifecycle in a little bit more detail. So uh on startup, if you double-click the add icon, then um a splash screen is shown so you see something is going on because it takes some time because the first thing it does is uh running the the the migrations and then starting the uh Django
Speaker 2: server. And then also the workers, background workers. And if everything is ready, then uh it will show a uh uh browser UI to the to the user. So this this is pretty straightforward And uh yeah, shutdown is a little bit more complicated. If the user quits the app, then all the background workers have to quit too, and the Django server has to quit. And mainjs has to wait briefly for all the processes exiting nicely and if they don't then it has to kill them at some point. And for for C L IQ this was also important because uh the simulations usually take up hours, if not days, and um
Speaker 2: if you accidentally press the close button button on a window and your simulation is uh termin is being terminated, this would user make user sad. So we had added a dialogue there, uh asking user Should we really terminate the simulation? And this has had to be done in the JavaScript part because this is the main. js process orchestrating the whole thing. Okay, uh let's have a look at the background tasks in the database. Yeah, uh in a in a big production website you would have a lot of services like a caching layer and maybe message queue stuff. We don't have any of that. We just have an SQLite database and background workers.
Speaker 2: Yeah, one user clicking around should be even enough for SQLite to scale up to, so it's not a problem. You need background workers because there's always work you need to do which is taking longer than you would usually expect from a HTTP request, like if you uh do imports of huge Excel files or run simulations or generate reports, stuff like that. Yeah, but this is this is a neat part. This is all working well and not not very different from a normal junk application. But then there are some details that are more difficult, hairy details like security.
Speaker 2: We are now running a real web server on the user's machine, so we have to kind of make sure that only legitimate requests are uh handled and um therefore we probably need to listen on on on local hosts only and um Then we have to also uh have CSIF protection for incoming data and tighten up load hosts too. Mitigate against DNS rebinding attacks because other browser windows can also, when when there's JavaScript, can interact with our server. But this is this is uh kind of Django stuff. I think most of the people here know that Unusual part is and and more complicated part is the electron part because by default JavaScript that runs in the electron application window
Speaker 2: uh can access the JavaScript uh on the on the Node. js backend and require file system and basically do uh rem yeah. code execution there. So if you have a cross-site script bug or something like that, it can become a remote execution bug, which is kind of you don't want to have. So you have to configure isolate the JavaScript running in the in the browser window from the JavaScript running in the backend. You have to configure a preload bridge that is minimal and stuff like that. And you have to do that because by default it's not on. So this is something you have to do or at least think about. Another difficult thing is packaging. Because
Speaker 2: one thing is in in in physics an electron is a really small and lightweight particle In uh software. We ship chromium with electrons that's not particularly lightweight. Uh and we also have to add a Python interpreter. We use Python standalone for that. Really cool project uh uh relocatable uh virtual env with UV It's also really, really important parts of the Python uh infrastructure there. And it's it's we I'm really glad that the Python stand-alone repository now has a stable and future-proof home at Astral, the makers of UV which now have also a really stable and future proof proof home at OpenAI. But yeah, so
Speaker 2: I hope hope the best. And um Yeah, we also bundled the Django apps and assets for those we we want to ship in our application. So the bundle can get pretty big. Yeah, then we also have the problem that we want to be able to run it on users machine. Mac OS is the most complicated thing platform there because You have to assign this app bundle and you you also have to notarize it, otherwise the gatekeeper process on macOS wouldn't let you start it. Uh yeah, this is kind of complicated. And also uh for for Windows you only have to sign, but this is also complicated. In the in the starter template, there's infrastructure for that. So if you fork the uh repository and add your secrets, it should work.
Speaker 2: works. You also need a Apple developer account. For Linux it's a little bit easier signing stuff and so but it's in other ways complicated so this is the whole packaging story is not not easy. But probably you only have to do it once and if it works then then don't touch it. So yeah. Ah, let's do something more fun. Live demo. I just show the small crot application. Ah no, I don't show it because where's the mmm? Maybe where's the monitor? Uh it's probably right or left. Ah, okay. It's on the right. Yeah, I can install it by just dragging the
Speaker 2: uh icon in the front of the disk image into the applications folder, which you can't see because it's on a different monitor. Uh-huh. Where's my mouse? Oh no. Ah here. Okay. So it appeared here, uh 350 megabytes of of application bundle, and if I click it. Should open uh splash ah no first of course uh warning dialogue because it's not via the app store, which is I don't know, it's bad probably. And um Yeah, no, the splash screen screen should be shown. Oh, but on the wrong window. Ah, I didn't thought of that. This is why you should use uh videos and not do the live demo
Speaker 2: like this, but okay. No, okay. Here's the window, this is the uh the the electron application Uh yeah, just normal normal uh trut trut thing, you can change stuff. And uh yeah, uh that's a thing just to show that it's possible to run background jobs. So and uh what's really uh really cool you can you can do stuff here that it's not possible usually on a website. So if you click this button. Then a local folder gets opened up, which is cool. Yeah, but it's also on the wrong window
Speaker 2: Which is kind of cool, but it's also kind of scary. But this is going through the preload bridge to the Node. js backend and then this is this is possible. What's also possible, also included in the SATA template, is um if I have a look at the version, it's uh 1. 5 and uh if you ship chromium you have to update often because all of the all the all the security issues And you have to update your application too because otherwise you you get the uh the issues from from Chromium. Um so you need a probably a way to auto-update the stuff. also included so I can just update to one point six.
Speaker 2: So you don't see the splash screen. This is really sad. But naja. Okay, so now it's started. Started again. And now it's having the updated version. So okay. So it it it it kind of works. Okay, I just uh start the presentation again. Okay, next time to video Okay, but uh
Speaker 2: yeah, that's I thought live doing is the fun part. No. Okay. Uh uh having having a little demo with Crowdapp is not really useful, but uh what what might be actually valuable is um wrapping an existing application. Maybe you have some some Django application you think, oh this would also be uh good as as a desktop application. So how to do that. Most of the parts stays the same. All the Django parts are nearly all of it stays the same. But there are things that have to change. If you deploy to a production server, you also have a different settings file. Maybe you you need to adjust some environment variables, stuff like that is pretty normal, okay
Speaker 2: But you also have to think about things like authentication because if you if you sit if you're the only user in front of a desktop application A login window, uh login form doesn't really make sense. So you have to think about ways on how to skip this or auto-authenticate. Maybe um and uh also navigation is different because um in a browser you have back and forward button and uh in an electron app There's no crowser uh browser Chrome, so uh you still want to have a way to go back to the root of your page or um uh go back And there are different ways you can do that. You can add that to the electron part of the application, or maybe in the HTML is also possible. Depends on your use case, but you have to think about that.
Speaker 2: Yeah, but it's it's uh lot lot more like deploying to a different system and uh than rewriting it. So I also did a small example to test the starter template. I have this small Django application called Django Resume for managing my CV and resume stuff. I'm the only user, it's a personal workflow, so I thought, okay, this is a good candidate to wrap it in an electron app. And um yeah, then I could have just copied and pasted this stuff from the starter template to the Django resume repository, but then thought okay maybe I can just use my my favorite uh slot machine to do the copy and pasting for me and therefore I wrote a skill so you can use it too uh by just
Speaker 2: calling UVX desktop Django starter rep and uh if you use the the the good models then uh it should also be able to one-shot it takes about fifteen minutes. But I would really be interested. I also tested on different Django apps and it kind of worked. If you have something different in mind or your own application that you want to wrap, let's let's maybe do it together after the talk because I'm really interested in how how good the skill generalizes and if there are Issues. But yeah, it should should somehow work. Okay. Additional thing, we should maybe have a look at some alternatives. Um
Speaker 2: yeah, electron is not the only uh thing you can use to wrap uh Django in a desktop uh desktop shell uh another one is tori and maybe if i had known about tori one year ago then we would have used that and not electron but I didn't know so but um Yeah, both are are kind of good. When is this is this a good idea maybe if your use case includes uh lots of local local data you don't have anywhere If you're offline in an air gap environment, have to connect to uh hardware devices via USB or something like that, uh you can't reach from a remote remote server, then desktop application might be the right choice.
Speaker 2: Or if you have heavy compute. This was also the case for Steel IQ. So each simulation took about 16 GHz of main memory. and um did run for hours and there's also a lot of data involved and all of just the virtual replicas with virtual env uh with the data science stack inside was well above one gigabyte. So for us, adding Electron in the Chromium browser wasn't really an issue. It was mere rounding error kind of addition. But Tauri uses less resources in this regard. So if you are resource constrained and it matters for your use case, then Tori is maybe a better option also. The security story is a little bit better in Tori. So this might uh and I also added this
Speaker 2: added to the starter template so you can also wrap your application in Tori if you if you like. Then there are pure Python alternatives like um PyBebiew, I didn't try that out, but the repository looks good looks great. Positron is the pure Python um electron alternative from the Beaver project, which is also good, but It's also included in the SATA template, but it's not it's it's not at as well tested as Tori and Electron and maybe not working that well. And um yeah, then things where you have trouble using Django at all is maybe if you target mobile platforms. You can still use it as a backend for the PVA, but uh running Django on iOS device locally, it
Speaker 2: might be possible somehow, but uh I wouldn't recommend that. And uh if you if you want to have the same look and feel across platforms then maybe things like Qt or Kiwi are interesting to you. Or if you want to have native look and feel but also be cross-platform, then maybe be Virtoga. That's also stuff you can try. Yeah. Okay. Um maybe to to summarize this whole thing uh once again. If you cannot run Django on a on a server, you can still do Django development. Most of the things stay the same. There are things you have to change and um which are not that easy, like
Speaker 2: are also interesting uh if you want to make data data science stack work on on Windows, on clean windows installed. So we had to do some really unholy things to make this work because uh we were building the application bundles on on GitHub Action runners where you can have Windows uh binaries built and macOS binaries. And you need to copy some DLLs into your relocatable virtual env and stuff like that so it works on clean Windows installs. It's uh yeah. Security story is complicated, packaging is not easy. Um But for CLIQ it wasn't really an issue because the the the issues we had with other things in the project were much bigger, so uh it was kind of worth it. But if you have a really small thing then it might be too much.
Speaker 2: So depends. You might also want to have a look at alternatives, Electron versus Tauri. have a look at your uh constraints regarding main memory usage or bundle size and uh platform requirements. Okay. And uh of course the general uh expert Python programming advice from David Beasley applies or you can just not do any of that. Thanks.
Speaker 1: Thank you very much. Hands are going straight up. We've got two at the front already.
Speaker 3: Thank you, that's really exciting to see and thank you for putting the that um GitHub repo together because That's gonna be the barrier. Um I've seen people doing this shipping frozen versions of their Python application where they just ship the PyYC files. I guess for privacy or security of the source code type concerns. Did have you experimented with that or is it? Uh
Speaker 2: frozen right the the compiled Python files. Uh yeah, but uh still um I I think you have to have um different different versions for different platforms. I think or uh things like Py installer, maybe th things like that, where you compile it into an Excel. Yeah, that's also possible. For for the um cute thing I do at the moment, I use Py installer. That's also possible. But um yeah, if you target uh wrapping a web application then electron autori is probably the best uh option you have at the moment but you can you can bring any uh any python application in in in a desktop uh setting It's uh but yeah. Okay. Oh
Speaker 4: thanks. Um if you want to export the data from your the state of your application uh out of the application, so you Just uh use a normal menu and you can just export a SQL dump from there or how does it work?
Speaker 2: Yeah of course. If you if you just uh or you can just copy the SQLite database, it's just a file on the disk. And uh yeah I don't know if it's uh if it's portable between platforms, but you can also have it in an an export of the of the database, just as SQL. That's that's perfectly possible, yeah It's not implemented. Pardon? Uh no. That's just the uh database on the disk.
Speaker 1: I think we've got another question over there.
Speaker 5: Yes, hello. Uh I just realized that if you ship your Django application in a Windows or Mac installer, you're also shipping all of your source code inside that installer. Is that a problem for your use case? And could you work around that
Speaker 2: uh I don't know. Yeah I I didn't even th think about that because we we ship our source code and it's not not a problem. But yes. Yeah I don't think it's really possible to you can obfuscate of course. You can, for example, just put it in a zip file, encrypt a zip file, and then try to hide the key for that encryption uh encrypted thing or something like that. That would be possible because you can import from a zip file. But uh Yeah, there's not really a way to compile Python code uh so that you can't get get it back right. So I I think it's you can have something like that, but it's uh would be uh a little bit a little bit work Yeah, but we we don't do any of that.
Speaker 2: We just chips the source code source code.
Speaker 5: Thanks.
Speaker 1: Thanks. I think we've got time for one more, if anyone has any. Yep.
Speaker 6: Um so I just saw that there's online a question. Maybe I can read it and uh it's from Thomas Turner. I did a talk in DjangoCon at Cardiff, UK uh years ago and on something very similar And I had a desktop app running in Django. It's been running for quite a few years. My question is, is the code secure? In other words, could somebody reverse engineer it? So it's more or less the same.
Speaker 2: You can probably get at the source code, I think, yes, because uh it depends a little bit on how you uh how you build your application bundle, but um I think usually uh you would be able to get the source code. And security, yeah, security is a problem. Also if you if you configure Electron correctly. It's possible to do that so that all is secure, but probably not by default and you have to invest some some thought into that. So yeah
Speaker 1: Thank you very much.
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