Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Run less code in production or you’ll end up paying the price later
Run less code in production or you’ll end up paying the price later At work we do have the problem of dependencies which aren’t maintained anymore. That’s actually a great problem to have because it means that the app or website ended up running for a long time, maybe longer than expected initially. I think that websites have a lifetime of 3-5 years1 which is already much longer than the lifetime of major versions of some rapid development frameworks, especially frontend frameworks. We have been using Zurb Foundation in the past. It has served us well and I don’t want to dunk on it – after all it is free, it has great documentation and it works well. It has many features and many components, but as changes happen, not just in the framework itself but also in the tooling it uses upgrades stay hard and things start to break somewhere down the road (for example when Dart Sass 2.0 will be released. And when that happens you have to pick up the parts and maintain them yourself – having grown your codebase by a considerable amount practically overnight. Of course it’s also hard to argue for starting to write … -
Top 10 Django Third-Party Packages
Django is a "batteries-included" web framework, but it really shines with its robust ecosystem of third-party packages that add additional functionality to the framework. There are almost 4,000 available at … -
Weeknotes (2023 week 13 and 14)
Weeknotes (2023 week 13 and 14) My son will be a teenager soon My eldest is now 12 years old and will be a teenager soon. We had a good time and two nice Birthday parties, one with his friends and one with family and our friends. Good times. django-debug-toolbar 4.0 Django 4.2 was released, Hatch gained support for the Django 4.2 Trove classifier and we released django-debug-toolbar 4.0, with support for Django 4.2, psycopg 3 and all the existing goodies. feincms3-cookiecontrol feincms3-cookiecontrol has gained support for consciously embedding stuff via oEmbed. It can now use Noembed (via feincms3‘s external plugin) and only actually embed the third party content if users consented explicitly. I have since learned through the Datenschutz-Plaudereien podcast that laws regarding consent are not that strict in Switzerland compared to the European Union, also not when the DSG is put into effect in September. What’s right and what’s legal are two different things and while I don’t really like the ubiquitous cookie banners (especially not when they aren’t actually doing anything) I like the idea of explicit consent and of not sending data unnecessarily to third party providers. The additional click isn’t that bad. Diving into hatch … -
How to add Typescript to the Django Project
-
Building an Intelligent Education Platform with OpenAI, ChatGPT, and Django
This tutorial shows how to build an intelligent educational platform using OpenAI APIs and Django. -
Django News - Django Behind The Scenes - Mar 31st 2023
Django Software Foundation DSF Board monthly meeting, March 9, 2023 The DSF Board meets monthly and posts its minutes publicly. Worth a quick look to see what's going on in the Django world. djangoproject.com Sponsored Link Looking for a fun new project? Try Wagtail CMS See why Django developers think Wagtail is a “joy to extend.” Trusted by Google, NASA, and many, many others. The #1 Django-powered CMS. Give it a go. bit.ly Articles Django: Avoid database queries in template context processors Advanced tips on using template context processors from Adam Johnson. adamj.eu Denormalization with JSON Fields for a Performance Boost A well-written article on normalization/denormalization with a powerful tip on using JSON Fields to help improve performance. caktusgroup.com Ban 1+N in Django An opinionated take on solving a perennial issue in Django and ORM's in general: the N+1 problem. github.io Sync or Async? Unpacking the Mysteries of Django Signals Signals allow developers to trigger certain actions when specific events occur, such as when a model is saved or deleted. However, there is often confusion about whether Django signals are asynchronous or not. This article explores the question and discusses the tradeoffs associated with using Django signals. mattlayman.com A Chat … -
Follow-ups to "Incompetent but Nice"
I received a ton of replies to my previous piece in “incompetent but nice” people. I’ve collected some of those replies, and some of my own follow-ups. I’ll cover: what managers should do; the theme that this is almost always a management failure; and my advice for people who are worried that they might be the “incompetent but nice” person. -
Ellen's Alien Game / Display Related / Neovim config - Building SaaS with Python and Django #157
In this episode, I did another Exercism problem in Python that focused on Python classes. After the exercise, I deployed my model change from last stream and discussed deployment strategy. Then we worked on some of the display pieces for the new feature. Once the feature was added, I discussed performance testing and showed some performance problems that the new feature created that I then fixed. We ended the stream with some Neovim configuration to correct some LSP formatting problems. -
Ellen's Alien Game / Display Related / Neovim config - Building SaaS #157
In this episode, I did another Exercism problem in Python that focused on Python classes. After the exercise, I deployed my model change from last stream and discussed deployment strategy. Then we worked on some of the display pieces for the new feature. Once the feature was added, I discussed performance testing and showed some performance problems that the new feature created that I then fixed. We ended the stream with some Neovim configuration to correct some LSP formatting problems. -
How Django Really Works - Chaim Kirby
Chaim on GitHubDjango Software FoundationDjangoCon Europe 2022: The Why and How of the Django Software FoundationDjangoCon Europe 2018: A Different Form of Navigationpyslackers.comDjangoCon US 2018 - Your web framework needs you!Support the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter. -
Incompetent but Nice
A question I’ve never been able to answer to my satisfaction: how do you manage people who are nice but can’t do the work? -
Django News - Django 4.2 released candidate 1 released - Mar 24th 2023
News Django 4.2 release candidate 1 released Django 4.2 release candidate 1 is the final opportunity for you to try out the farrago of new features before Django 4.2 is released. djangoproject.com Want to host DjangoCon Europe 2024? Could your town - or your football stadium, circus tent, private island or city hall - host this wonderful community event? djangoproject.com Welcome to the PyPI Blog Announcing the launch of blog.pypi.org pypi.org Sponsored Link Supercharge Your Wagtail CMS Project Implement Wagtail at scale by adding extra capacity and capability to your sprint team with Torchbox's Consultancy and Staff Augmentation services. Utilised by Mozilla Foundation, Nasa JPL, and the NHS. Find out more: https://bit.ly/wagtail-super-boost bit.ly Articles Django: Parameterized tests for all model admin classes An application of "test smarter, not harder" for any project using Django's admin. adamj.eu A 'No JS' Solution for Dynamic Search in Django Take advantage of HTMX requests to do partial rendering for list views in Django. fly.io Django Database Connection Pooling with PgBouncer An example of Django PostgreSQL Database Connection Pooling with PgBouncer. github.io Locking Down Your Users' Secrets: Django Sessions 101 Explore the security of Django sessions and see how they can be made even more … -
Weeknotes (2023 week 11 and 12)
Weeknotes (2023 week 11 and 12) Mail user agents being mail user agents django-authlib is my collection of utilities for implementing passwordless authentication, either using OAuth2 or by sending magic links by email. The latter functionality has existed for a long time in django-registration (which is great!) but I wanted a way to generate links without the need for a storage somewhere. Django has utilities for Cryptographic signing built-in as the django.core.signing module. I’m using this module to send a signed version of the email address to users, and when I’m able to successfully verify the email addresses signature I can be sure (enough) that those links have actually been generated by my code. The form of the generated verification URL is as follows: https://example.com/.../test@example.com:1pXJtx:aypKOlb5zaCg.../; the part before the first colon contains the data-to-be-verified, the short string between colons is the timestamp and the rest is the signature, everything generated by django.core.signing. So far so boring. But then mail user agents happened. Some MUAs insist to butcher the URL in various ways, e.g. by removing the signature or by making only the embedded email address clickable. This is “interesting” behavior and certainly unexpected. Last week I implemented a change where … -
Django: Avoid database queries in template context processors
Django’s template engine allows you to augment template contexts with context processors. These are functions that take the current request and return a dictionary to be merged into the context: from example.models import HotDog from example.models import HotDogState def hot_dog_stats(request): return { "hot_dogs_eaten": HotDog.objects.filter( state=HotDogState.EATEN, ).count(), } You enable context processors by pointing to them in the TEMPLATES setting: TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "OPTIONS": { "context_processors": [ ..., "example.context_processors.hot_dog_stats", ..., ], }, }, ] Django’s startproject template includes a few context processors, such as the one from django.contrib.auth that adds the user and perms variables. Context processors are convenient for adding extra “global variables” to templates. But because they run on every top-level template render, they need to be robust and performant. In particular, avoid running database queries within them. Database queries within a context processor can have at least two negative consequences: Performance impact If a context processor fetches data that is not used when rendering a page, the resources spent fetching the data will have been wasted. Since most sites contain different types of pages, pretty much any query run in a context processor will be wasted on some pages. For example, your Django Admin pages … -
Locomotive Engineer / New Model Field - Building SaaS with Python and Django #156
In this episode, I did another Exercism problem in Python that focused on Python packing and unpacking of arguments. Once the exercise was complete, I started on a new feature with the homeschool app. We added a new model field in preparation for the changes. After that, I removed django-stubs because it wasn’t a good fit for my project. -
Locomotive Engineer / New Model Field - Building SaaS #156
In this episode, I did another Exercism problem in Python that focused on Python packing and unpacking of arguments. Once the exercise was complete, I started on a new feature with the homeschool app. We added a new model field in preparation for the changes. After that, I removed django-stubs because it wasn’t a good fit for my project. -
Django Performance Optimization Tips
This article looks at where potential performance issues can occur in a Django application and how to address them in order to speed up your app. -
How to Automatically Switch to Rosetta With Fish and Direnv
I love my Apple silicon computer, but having to manually switch to Rosetta-enabled shells for my Intel-only projects was a bummer. -
Locking Down Your Users' Secrets: Django Sessions 101
Django is a powerful and popular web framework that makes it easy to build robust and secure web applications. One of the key features of Django is its ability to manage user sessions, which are essential for many web applications. However, you may be wondering if Django sessions are secure. In this article, we’ll explore the security of Django sessions and see how they can be made even more secure. -
Django News - DjangoCon US 2023 Preview - Mar 17th 2023
Sponsored Link Meet Wagtail, the #1 Django-powered CMS 100% open source. Powered by Python & Django. Built for editors and developers with excellent documentation. Trusted by Google, NASA and hundreds of thousands of organisations around the world. bit.ly Articles How virtual environments work A comprehensive look at how virtual environments work to help demystify them. snarky.ca Time Travel with django-simple-history A closer look at django-simple-history, a third-party Django package that provides model version control, including who made the change, when it was made, and the difference. mattlayman.com Marketing for Developers A reasonably comprehensive list of steps one can take for their projects to get more visibility. alldjango.com How migrate an existing Joomla CMS website to a Django Backend Migrating a Joomla based website to a Django Backend with 90 Gb worth of data. adonissimo.com Caching and Django Rest Framework How and when to cache a Django API, as well as advice for when NOT to. screamingatmyscreen.com Design Articles An end to typographic widows on the web Currently shipping in Chrome Canary, and thus soon to be in Blink-based browsers, including Edge, is a relatively new CSS declaration that promises to end typographic widows virtually. clagnut.com Sponsored Ad Upgrade Django Upgrade … -
Django: Parameterized tests for all model admin classes
Here’s an application of “test smarter, not harder”, as per Luke Plant’s post. I came up with this recently whilst working on my client Silvr’s project, and I’m pretty proud of it. It should apply to any project using Django’s admin. When you declare a Django ModelAdmin class, the built-in system checks ensure that various attributes are well-defined, using the right data types and values. But they can’t cover everything, because there is so much flexibility. So it’s possible to have, for example, a bad field name in search_fields. You can ensure that a ModelAdmin class works properly by writing tests to load its various views. But rather than write individual tests, you can “push down the loop”, and write parameterized tests that run on every ModelAdmin. The below code tests all model admins’ “changelist” and “add” pages. It’s all generic, so you should be able to copy-paste it into most Django projects without modification. from __future__ import annotations from collections.abc import Callable from http import HTTPStatus from typing import Any from django.contrib.admin.auth.models import User from django.contrib.admin.sites import AdminSite from django.contrib.admin.sites import all_sites from django.db.models import Model from django.test import TestCase from django.urls import reverse from parameterized import param from … -
Cater Waiter, Template Bugs, and Type Fixes - Building SaaS with Python and Django #155
In this episode, I did another Exercism problem in Python that dug into Python sets. Once the exercise was complete, we went back to the issue list. I debugged and fixed a template error, the spent time improving types with my Django app. -
Cater Waiter, Template Bugs, and Type Fixes - Building SaaS #155
In this episode, I did another Exercism problem in Python that dug into Python sets. Once the exercise was complete, we went back to the issue list. I debugged and fixed a template error, the spent time improving types with my Django app. -
DjangoCon US 2023 - Drew Winstel
Drew’s Personal Site@drewbrew on Mastodon and https://takahe.social/@drewDjangoCon US 2023 and on GitHubDjango Events Foundation North America (DEFNA)Drew’s 2018 DCUS talkDCUS call for volunteersSponsor DCUS 2023 https://thenounproject.com/icon/dumpster-fire-4367573/HSV.beer, on Instagram and on GitHubDrunk: How We Sipped, Danced, and Stumbled Our Way to CivilizationEast Coast GreenwayAmerican Tobacco Trail 14 miles paved, 22 total; directions from the hotel to the trailheadSupport the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter. -
Caching and Django Rest Framework
One of my current projects involves an API. Not surprising in the year 2023. During business hours data is primarily read. Payloads are large and the underlying data model is as complex as it needs to be. Lots of data and a complex data model is usually a good way to make sure your API is slow. And this project was no exception. While there are many different ways how you can approach this, I opted for the one with the smallest change to the codebase possible and the least amount of change required in the existing infrastructure. Let us start with a small list of reasons why this approach made sense for this particular project. I would not advocate using it as a general design pattern every time you run into performance issues. Data is mostly refreshed during night time. There might be four or five manual edits during day time for every 100,000 entities stored. The project is still in its early MVP / prototyping phase. Not introducing additional service requirements simplifies deployment and workflows. The API is read only. Not introducing additional services and hunting data through different data stores also means debugging potential issues is simple. …