Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Weeknotes (2025 week 03)
Weeknotes (2025 week 03) Claude AI helped me for the first time django-imagefield prefers processing thumbnails, cropped images etc. directly when saving the model and not later on demand; it’s faster and also you’ll know it immediately when an image couldn’t be processed for some reason instead of only later when people actually try browsing your site. A consequence is that if you change formats you have to remember that you have to reprocess the images. The Django app comes with a management command ./manage.py process_imagefields to help with this. I have added parallel processing based on concurrent.futures to it some time ago so that the command completes faster when it is being run on a system with several cores. A work colleague is using macOS (many are, in fact), and he always got multiprocessing Python crashes. This is a well known issue and I remember reading about it a few years ago. I checked the docs and saw that the concurrent.futures page doesn’t mention macOS, but multiprocessing does. So, I hoped that a simple rewrite of the management command using multiprocessing might fix it. Because I was in a rush and really didn’t want to do it I turned … -
Thinking About Risk: Sidebar #1: "Exposure"
Risk is usually defined as the product of two factors: Likelihood and Impact. However, some disciplines include a third factor: Exposure. What’s that about, and when is it useful? -
Don’t automate screenshots, automate iframes
There’s a lot of tools out there to automate taking screenshots for documentation of web apps/libraries. Screenshots are certainly sometimes a good idea, but they have some serious downsides: As you’re sending pixels instead of text, screen readers don’t work Screenshots adjust badly to zoom levels Responsive layouts don’t work Automatic dark mode selection doesn’t work They are larger to download They are hard to generate They are slow to generate When writing the iommi documentation I realized that I can bypass all that by using embedded iframes instead of screenshots. Instead of spinning up a headless Chrome, writing playwright/selenium automation and suffering through all that, I can render the page I am documenting like normal, and save the html to disk, which is then linked to with an iframe. It required some custom tooling, but check out the iommi cookbook for examples and I think you’ll agree the results are pretty great. Here’s a sample test from the cookbook that generates the iframe, and then the rST file for the docs: def test_how_do_you_turn_off_pagination(small_discography): # language=rst """ How do you turn off pagination? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Specify `page_size=None`: """ table = Table( auto__model=Album, page_size=None, ) # @test show_output(table) # @end The show_output … -
Migrating from Hyde to Hugo
Almost twelve years after the last big site infrastructure change, it’s time for another round. This time is purely technical, with no intentional visual changes. Motivation I haven’t posted in a long time, and this blog had largely faded into the background for me. I was doing some management of my domains, trying to clean things up after my domains registered with Google were transferred to Squarespace. As part of this, I decided to use Cloudfare as my nameserver, which I’ve used for other projects. I started reading about Cloudfare Pages, which seemed like a great match for easily deploying a statically-generated site. You can point Cloudflare to a GitHub repo, and it will automatically kick off a build after every commit, and deploy the static artifacts. Unfortunately, the Hyde framework I was using is no longer maintained, and still does not support Python 3. Cloudflare Pages does not have support for Python 2.7. So I decided it would be a fun project to migrate to a new static site generator. Finding a new tool Searching around, I quickly settled on Hugo due to its large community, and reputation for blazing fast speed. I wasn’t quite sure how the easy … -
Creating Open Graph Images in Django for Improved Social Media Sharing
Although social media algorithms usually discourage posting links so that users stay as long as possible on the network, people often still post links below an introductory post as a comment or reply. Normal links to websites on social media look pretty dull unless you add open-graph images representing that link. In this article, I will show you how you can generate open-graph images for a Django website using web rendering from HTML and CSS. I rely on this technique to generate Open Graph previews for links from DjangoTricks, 1st things 1st, and PyBazaar. What is an Open Graph? Facebook created the Open Graph protocol to allow websites to provide rich representation of any web page. Although it has specifics for websites, articles, profiles, music, and video, the common use case is to have a preview image with a title for social feeds. Open Graph previews work with most well-known social networks, including Facebook, Threads, LinkedIn, Mastodon, and Blue Sky. Open Graph tags are HTML meta tags that you put in the HEAD section, e.g.: <meta property="og:type" content="website" /> <meta property="og:url" content="{{ WEBSITE_URL }}{{ request.path }}" /> <meta property="og:title" content="{{ profile.user.get_full_name }}" /> {% if profile.open_graph_image %} <meta property="og:image" content="{{ … -
Django News - CFPs for DjangoCon Europe and DjangoCongress JP - Jan 10th 2025
News Feedback needed on Content-Security-Policy header support Rob Hudson is seeking feedback on Content-Security-Policy header support and asking for input before Django 5.2's feature freeze by January 15. mastodon.social Django Software Foundation DSF member of the month - Hiroki Kiyohara Hiroki is the creator and a staff member of DjangoCongress JP. He has done a lot for the Django Japan community and has been a DSF member since October 2024. djangoproject.com DSF Board monthly meeting, January 9, 2025 DSF Board monthly meeting minutes for January 9, 2025. djangoproject.com Updates to Django Updates to Django Last week we had 17 pull requests merged into Django by 11 different contributors - including 3 first-time contributors! Congratulations to Ari Pollak, Chaitanya Rahalkar and Harsha Vardhan V for having their first commits merged into Django - welcome on board! Django Newsletter Sponsored Link 1 Django & Wagtail Hosting for just $9/month New year, new site! Finally put those domain names to use and launch that side-project, blog, or personal site in 2025. Lock in this limited time pricing by Feb 28. codered.cloud Articles Django: Fail in templates with {% url '' %} Crashing Django templates on purpose is easier than you might think—just use … -
Simplified Signup - Building SaaS #211
In this episode, we began an update to the signup process to simplify things. I am replacing email and password with just email. Users will receive ‘magic links’ via their email client to sign in. To do this, we are using django-sesame. -
Django: render JavaScript import maps in templates
JavaScript’s import statement lets module scripts import objects from other scripts. For example, you can define a script as a module in HTML: <script type=module src="/static/js/index.js"></script> Then that file can import from another, like: import { BigBlueButton } from "/static/js/lib/buttons.js"; // ... This syntax will work within the context of a Django project, but it’s not ideal. You typically want to render static file URLs with {% static %} rather than hardcode them like /static/js/lib/buttons.js. This way, if you’re using the popular Whitenoise package or Django’s built-in ManifestStaticFilesStorage, the rendered asset URLs will have cache-busting hashed filenames. But you can’t use {% static %} within JavaScript files (without templating them, which prevents you from using other JavaScript tooling on the files, such as Biome). Django 4.2 added experimental import statement rewriting to ManifestStaticFilesStorage. This feature makes collectstatic modify import statements in collected JavaScript files to use hashed filenames. For example, if used on the above file, it might output: import { BigBlueButton } from "/static/js/lib/buttons.decac99afbe8.js"; // ... To activate it, subclass ManifestStaticFilesStorage and set the support_js_module_import_aggregation attribute to True (documentation). But this is marked experimental due to Ticket #34322, which I reported, showing that the changes could break code using … -
Django in 2025
LearnDjango Three Course BundleThe Stack ReportLeuchtturm Weekly PlannerRereading Working in Public Fosstodon Thread DjangoCon Europe CFP Open Until January 12thAn Obvious Statement About Open Source | Christopher Neugebauer | Monktoberfest 2024Django 6.x Steering Council Results DjangoCon Japan, Europe, Africa, and USReimagining OSS Licensing and Commercialization with Fair Source - Adam Jacob, System Initiative -
Django: silence “Exception ignored in ... OutputWrapper”
You might see this message when running pytest on your Django project: $ pytest ... Exception ignored in: <django.core.management.base.OutputWrapper object at 0x108576170> Traceback (most recent call last): File "/.../django/core/management/base.py", line 171, in flush self._out.flush() ValueError: I/O operation on closed file. The message doesn’t fail tests but reports an unraisable exception that occurred inside Django. This is an exception at a point that Python cannot crash the program. It’s triggered by a bug in Django’s OutputWrapper class, which is used to wrap output in management commands when used in combination with pytest’s output capturing. The message can appear twice, once for sys.stdout and once for sys.stderr, for each management command tested for an exception, like: with pytest.raises(CommandError) as excinfo: call_command(...) This message is always visible on Python 3.13+, but it can also appear on older versions when using Python’s development mode, like: $ python -X dev -m pytest (I recommend using development mode locally and on CI; it activates several useful features!) I reported and fixed the underlying issue in Ticket #36056. The commit is scheduled for release in Django 5.2 and will not be backported to older versions. So, until 5.2 is out, your test output can get cluttered with … -
Comment remplacer une chaine par une autre dans le champ d’un Model Django
Je me suis retrouvé il y a quelques temps avec une problématique, remplacer une chaine par une autre dans un attribut CharField d’un model django. La première possibilité était de faire tout simplement une belle boucle sur la totalité de mes instances de module, faire le remplacement en python et sauvegarder la nouvelle valeur. Sauf que j’avais quasiment un million d’objet et que je n’avais pas envie que cela prenne des plombes. Et puis c’était un peu moche. Du coup j’ai un peu fouillé et miracle, j’ai trouvé une solution que voici. On commence par définir la fonction de remplacement, tout en django et en SQL. from django.db.models import F, Func, Value def replace_func(field_name, old_str, replace_str): return Func( F(field_name), Value(old_str), Value(replace_str), function='replace' ) Ensuite, il n’y a quasiment plus rien à faire. On va simplement appeler update sur tout les objets et utiliser replace_func. Par exemple : MonModele.objects.filter(CONDITIONS).update( champ_a_modifier=replace_func("champ_a_modifier", "str_que_lon_veut_remplacer", … -
Django News - 🎊 DjangoCon US 2025, Wagtail Updates, and Tips for Django Developers - Jan 3rd 2025
News DjangoCon US 2025 has been announced! DjangoCon US 2025 is heading to Chicago this September 8 - 12th—mark your calendar, prepare your talk submissions, and join the excitement! defna.org Wagtail CMS Wagtail 6.3.2 Wagtail 6.3.2 includes three bug fixes and a docs update. github.com Articles Database optimization isn't always obvious Database query optimization often defies intuition—Ken Whitesell unpacks why benchmarks, query plans, and context matter more than surface assumptions. github.io Python: create temporary files and directories in unittest Create and manage temporary files and directories in Python tests, with practical tips for unittest and more. adamj.eu Django in 2024 Django proved its versatility in 2024, powering everything from high-traffic APIs to async workflows, while keeping complexity low and teams productive—reminding us why it's still a top choice for modern web development. screamingatmyscreen.com Show Django flash messages as toasts with Htmx Learn how to display Django messages as user friendly toasts with Htmx joshkaramuth.com Getting Started Contributing to Django A collection of resources to help you get started contributing to Django. better-simple.com Introducing Django Template LSP: Smarter Completions for Django Templates - Four Digits Django Template LSP revolutionizes template editing with intelligent autocompletion, navigation, and hover docs, making Django development … -
My 2024 in review
A quick review of my 2024 done in a hurry, trying to remember the many experiences I had, the people I met, the places I visited and the changes I went through. -
Deploying a Django App to AWS ECS with AWS Copilot
This tutorial looks at how to deploy a Django app to AWS ECS with AWS Copilot. -
Django in 2024
2024 was a busy year for me. My clients really kept me on my toes with lots of fun and exciting R&D projects. Nearly all of them were built on the same stack. Some are internally facing, processing about 1.5 million messages asynchronously per day, some are customer facing, with a few hundred requests per second peak, but overall still nothing too crazy. I am sure they will get a bit more traction in 2025. Additional to that we worked on a non profit side project that will likely go online in January. I obviously did not write all these projects from start to finish by myself. For the first four to eight weeks I worked mostly alone on these projects. But during this time there were still other engineers to brainstorm, figure out the API for integration points, get some help with customer specific domain questions and have a project or product manager track down external information that were needed. I was just the lucky one to write code all day and I got to push these things to production for the first time. Which is also the point when we usually brought in more people to add features, … -
Django News - New Django Accessibility Team Members, Performance Pitfalls, and PyCon US 2025! - Dec 27th 2024
News Welcome to our new Django accessibility team members The Django Accessibility Team welcomes new members Eli, Marijke, Tushar, and Saptak, who bring valuable expertise to the project. djangoproject.com Articles Django: avoid using .first() when retrieving a unique object Avoid using .first() to retrieve unique objects in Django to avoid unnecessary performance costs from added ordering; instead, use .get() with proper exception handling for efficiency. github.io This Django Template Tag is Killing Your Performance Avoid performance pitfalls by replacing the length template filter with count() for QuerySet objects to prevent excessive memory and database usage. mirat.dev Better Error Tracking in Django Learn how to enhance error tracking in Django with Bugsink. Explore built-in features, limitations, and robust solutions for debugging and managing errors effectively. bugsink.com Loopwerk: Why I still choose Django over Flask or FastAPI Django's comprehensive features, powerful ORM, seamless migrations, and supportive community make it the go-to choice for building versatile and scalable applications. loopwerk.io Events PyCon US 2025 Registration is open! PyCon US 2025 registration is open, offering flexible rates, early bird discounts, and a packed schedule of events, including tutorials, keynotes, and sprints. pycon.org Podcasts Django Brew: Episode 4: Spoiler Alert: DjangoCon US Recap, Open Source … -
Optimizing SQLite - Building SaaS #210
In this episode, when worked on the newly migrated JourneyInbox site and focused on the database. Since me moved from Postgres to SQLite, I needed to make sure that SQLite was ready for users. We examined common configuration to optimize the database and applied that config to JourneyInbox. -
Django: Fail in templates with {% url '' %}
Previously, I covered using 1/0 to crash Python within minimal typing, useful to quickly answer questions like “does the code even get here?”. Recently, I wanted to do the same in Django templates, to trace if a given template was even being rendered, and under which code paths. It’s a bit more challenging to deliberately crash Django’s template language, since the whole system is designed to be robust, silencing of many kinds of errors. The language is also restricted, so {{ 1/0 }} doesn’t work, as variables cannot contain expressions. Still, after playing around for a bit, I came up with following two options. First, there’s a way to run 1/0, using divisibleby: {{ 1|divisibleby:0 }} On rendering, this raises a classic ZeroDivisionError: ZeroDivisionError: integer modulo by zero That said, divisibleby is a bit long and tricky to type. Second, my preferred method uses the url tag: {% url '' %} The {% url %} looks up URLs by name, so providing it the empty string forces no URL to match, raising a NoReverseMatch error: NoReverseMatch: Reverse for '' not found. '' is not a valid view function or pattern name. I don’t think there is a shorter way to crash using … -
Why I still choose Django over Flask or FastAPI
I started using Django in 2009, and fifteen years later I am still a happy user. Why do I prefer it over Flask or FastAPI? -
Weeknotes (2024 week 51)
Weeknotes (2024 week 51) Building forms using Django I last wrote about this topic in April. It has resurfaced on Mastodon this week. I’m thinking about writing a feincms3-forms demo app, but I already have too much on my plate. I think composing a forms builder on top of django-content-editor is the way to go, instead of replacing the admin interface altogether – sure, you can always do that, but it’s so much less composable… Releases blacknoise 1.2: No real changes, added support for Python 3.13 basically without changing anything. It’s always nice when this happens. django-imagefield 0.21 django-prose-editor 0.10: I rebuilt django-prose-editor from the ground up and wrote about that two weeks ago. The 0.10 release marks the final point of this particular rewrite. django-js-asset 3.0: See the blog post from this week -
Django News - Django 6.x Steering Council Election Results - Dec 20th 2024
News Django 6.x Steering Council Election Results Congrats to our new Steering Council members. Carlton Gibson Emma Delescolle Frank Wiles Lily Foote Tim Schilling djangoproject.com Django Reached 100%+ Funding! Django successfully reached its funding goal of $200,000 for 2024. It speaks to the volunteer-nature of the project that something with so many moving parts and active contributions can thrive on such a relatively limited budget. djangoproject.com Python Insider: Python 3.14.0 alpha 3 is out This is an early developer preview of Python 3.14 featuring several major new features compared to Python 3.13. blogspot.com Django Software Foundation Today 'Updates to Django' is presented by Velda Kiara from Djangonaut Space! Last week we had 14 pull requests merged into Django by 11 different contributors - including 3 first-time contributors! Congratulations to Juan Pablo Mallarino, Ben Cardy, and amansharma612 for having their first commits merged into Django - welcome on board!🎉 Here are some highlights from the recent updates coming to Django 5.2: The migrate and runserver commands now respect the requires_system_checks override, running only the checks tagged with the specified tags. A new hook, get_check_kwargs(), allows for further customization. django.urls.reverse has been enhanced to support query strings and URL fragments, offering more … -
Bootstrap Kamal On Droplet - Building SaaS #209.1
In this episode, I worked to finish the cloud migration to DigitalOcean for JourneyInbox. We started the stream by bootstrapping Kamal on the server. I hit network issues so this stream is split into multiple parts and is of lower quality than normal. -
Docker Image For Kamal - Building SaaS #209.2
In this episode, the second portion of the stream worked on fixing up the Docker image so that we could get the DigitalOcean droplet functional. This is the second stream chunk because I was having network issues and the first stream cut out. -
Postgres To SQLite - Building SaaS #209.3
In this episode, the third portion of the stream covers how I migrated my Heroku-backed Postgres database to SQLite. I finished the migration of my app from running on Heroku to running on DigitalOcean. -
Object-based assets for Django's forms.Media
Object-based assets for Django’s forms.Media The pull request for adding object-based script media assets into Django is in a good state and I hope it will be merged soon. I have been using object-based assets long before Django actually added support for them in 4.1 (since 2016, that’s before Django 1.10!) by using a gross hack. Luckily I have been able to clean up the code when Django 4.1 landed. I have been asking myself at times why I haven’t proposed the change to Django myself despite having been a user of something like this for such a long time. After all, I have been happily contributing issue reports, bug fixes and tests to Django. The process of adding new features sometimes is terribly frustrating though even when looking (and cheering) from the sidelines. It feels bad that adding another package to the list of packages I maintain so clearly seems to be the better way to get things done compared to proposing a new feature for Django itself. I hope processes change somewhat. But I digress. The ProseEditorWidget in django-prose-editor wants to ship CSS, JavaScript and some JSON to the browser for the widget. So, of course I used …