django-planet

Blog: Adam Johnson

web https://adamj.eu/
Author Adam Johnson

Django: Fuss-free use of Homebrew GDAL/GEOS libraries on macOS

March 20, 2024 » Adam Johnson » [Archived Version]

GeoDjango requires the GDAL and GEOS spatial libraries. On macOS, you can use Homebrew to install these, but they won’t be picked up by default since they live in a non-default library directory, /opt/homebrew/lib. Django will fail to start with an exception: Traceback (most recent call last …

Read More

Django: Join the community on Mastodon

Feb. 10, 2024 » Adam Johnson » [Archived Version]

Mastodon is a Twitter-like social network with a solid Django community presence. It’s a fantastic online arena for connecting with others, discovering news, discussing issues, and sharing FOMO-inducing conference photos. Historically, Twitter was the primary social network for the Django community, as for much of tech. But since Elon …

Read More

pre-commit: Block files based on name with a custom “fail” hook

Jan. 24, 2024 » Adam Johnson » [Archived Version]

This post is an adapted extract from my book Boost Your Django DX, as updated last week. pre-commit’s “fail” virtual language fails all files that it matches. Combine it with pre-commit’s file name and type matching to block unwanted files in your repository. Let’s try it out …

Read More

Boost Your Django DX update out now

Jan. 17, 2024 » Adam Johnson » [Archived Version]

I just released a major update to my 2021 book Boost Your Django DX. This update contains new content, a bunch of edits, and uses the latest versions of tools, including Python 3.12 and Django 5.0. Boost Your Django DX contains many recommendations to improve your development experience …

Read More

PostgreSQL: Full text search with the “websearch” syntax

Jan. 3, 2024 » Adam Johnson » [Archived Version]

PostgreSQL’s powerful full text search feature supports several query syntaxes. Of these, a website search feature should typically pick the websearch syntax. websearch copies some features from popular search engines, as covered below, offering familiar short syntax to users. It is also forgiving and will never raise a syntax …

Read More

Boost Your DX bundle deal update

Dec. 29, 2023 » Adam Johnson » [Archived Version]

My two “Boost Your DX” books are available in a bundle deal, saving $10 compared to buying them separately. Great for improving your Django and Git skills at the same time. Buy the bundle on Gumroad This offer does not apply to team licenses. I initially created a bundle deal …

Read More

Django: Detect the global privacy control signal

Dec. 27, 2023 » Adam Johnson » [Archived Version]

Global Privacy Control (GPC) is a specification for web browsers to signal website operators not to share or sell the user’s data. This signal is intended to exercise legal data privacy rights such as those provided by the California Consumer Privacy Act (CCPA) or the EU’s General Data …

Read More

Django: Sanitize incoming HTML fragments with nh3

Dec. 13, 2023 » Adam Johnson » [Archived Version]

A fairly common situation in a Django project is where you need to store and serve arbitrary HTML fragments. These often come from forms with rich text editors (using HTML’s contenteditable). It’s insecure to trust user-generated HTML fragments since they can contain naughty content like: <script src=https …

Read More

Django Quiz 2023

Dec. 11, 2023 » Adam Johnson » [Archived Version]

This evening I held a quiz at the December London Django Meetup Group. The quiz is a regular tradition: this was the fifth quiz that I’ve presented, and the sixth overall. Here it is so you can try it at home - answers are at the bottom. Dates refer to …

Read More

Django: Defer a model field by default

Dec. 11, 2023 » Adam Johnson » [Archived Version]

Some models have one or a few large fields that dominate their per-instance size. For example, take a minimal blog post model: from django.db import models class Post(models.Model): blog = models.ForeignKey("Blog", on_delete=models.CASCADE) title = models.TextField() body = models.TextField() body is typically many times larger …

Read More