200 Posts Tagged ‘django’ (Page 4)

(All tags.)


Django: use partial() with transaction.on_commit() to avoid late-binding bugs

Django’s transaction.on_commit() allows you to run a function after the current database transaction is committed. This is useful to ensure that actions with external services, like sending emails, don’t run until the relevant data is definitely saved.

Read more...

Django: Run a migration “by hand”

Normally your Django project’s deploy process runs the migrate command, and that takes care of updating your database as necessary. Especially on smaller databases, Django’s migration system can “just do it” for you.

Read more...

How to Patch Requests to Have a Default Timeout

Python’s requests package is very popular. Even if you don’t use it directly, it’s highly likely one of your dependencies does.

Read more...

How to optimize PostgreSQL queries from Django using pgMustard

Slow queries happen, and when they do, it can be tough to dissect why they’re slow. This difficulty is compounded by using Django’s ORM, since it generates the SQL for you, so you may have little idea of the actual queries “under the hood”.

Read more...

Django: how to be a teapot

HTCPCP, or Hyper Text Coffee Pot Control Protocol, was published as an April Fool’s joke 24 years ago today. It’s an HTTP extension for controlling coffee pots, and whilst it is a joke, it appears in various places around the web.

Read more...

Django: Raise an error for missing template variables

It’s all too easy to forget to pass a variable to your template or make a typo in a variable name. Unfortunately, it can be quite hard to debug such mistakes, since Django’s default behaviour is to ignore the problem and render an empty string.

Read more...

You probably don’t need Django’s get_user_model()

Django’s authentication system, django.contrib.auth, provides a built-in User model class. You can swap this to a different class with the AUTH_USER_MODEL setting, most easily at the start of the project.

Read more...

django-htmx Now on Read the Docs

I’ve just released django-htmx 1.9.0. As part of this release, it now has a documentation site built with Sphinx, hosted on Read the Docs at django-htmx.readthedocs.io.

Read more...

Announcing WhiteNoise 6

WhiteNoise is a simple solution to serving static assets. It lets you skip configuring a separate web server for your static assets, and serve them straight from Django. It’s a brilliant tool. I’ve used it for years on various projects, and I’ve recommended it many times, and mentioned it in several blog posts.

Read more...

Django: serve source maps with contrib.staticfiles

Source maps are files that map your minified CSS or JavaScript back to the original code. They allow you to use your browser’s development tools to debug minified code as if it were the original. Also some error capture tools, such as Sentry, can use source maps to report errors for the original code.

Read more...

A Problem with Duplicated Mutable Constants

Here’s a small problem I’ve seen where several modules share versions of the same “constant” variable. It came up in the context of a Django project with multiple settings files, but it could happen in different contexts.

Read more...

On Receiving the Malcolm Tredinnick Award

In December I was awarded the Malcolm Tredinnick Award. This is an annual award, selected by nominations from anyone in the Django community. I’m incredibly honoured to have been selected, joining a fine list of past recipients. I’ve been inspired by every one of them.

Read more...

How to Add a Favicon to Your Django Site

Your site’s favicon appears in the browser tab, and is a key way to brand your site. Setting up a favicon is a simple task, but once you start considering vendor-specific icons, it becomes more complicated.

Read more...

Set up EditorConfig for your Django project

The “tabs versus spaces” war is scheduled to rage on until the heat death of the universe. And whilst the Python ecosystem is firmly in the “spaces” camp, there remain numerous other text formatting options.

Read more...

Book-Driven Development from “Boost Your Django DX”

On Monday I released my new book “Boost Your Django DX”. It covers many tools and practices that are useful for developing Django projects.

Read more...

“Boost Your Django DX” Released

My new book, Boost Your Django DX is out now. I’m so glad it has shipped and I can relax, a bit 😅

Read more...

My Third Appearance on Django Chat

I’ve again had the pleasure of joining Carlton and Will on the Django Chat podcast, in Episode #105. They moved fast with this one - we spoke yesterday, and the podcast is live today!

Read more...

Today’s Django Security Release Deconstructed (4.0.1, 3.2.11, and 2.2.26)

Happy new year, and happy new upgrade! Django has issued a new security release today. This is the first set of security fixes that I’ve been involved in, so I thought I’d take the opportunity to explain the issues in a bit more depth.

Read more...

Set up a Gunicorn Configuration File, and Test It

If you use Gunicorn, it’s likely you have a configuration file. This is a Python module that contains settings as module-level variables. Here’s an example with some essential settings:

Read more...

Django: introducing django-browser-reload, for automatically refreshing your browser during development

Hitting “refresh” to see your changes is an instinct many web developers develop. But it’s a small waste of time that adds up to many hours per year spent waiting. It’s a sub-optimal development experience (DX).

Read more...

Preorder My New Book: Boost Your Django DX

Developer Experience (DX) is a catch-all term for anything that can improve your development workflow. Such improvements can help you write better code, faster, with fewer bugs.

Read more...

Three more uses for functools.partial() in Django

I remain convinced that Python’s functools.partial() is underappreciated. Following my previous post, here are three more ways to use partial() with Django.

Read more...

New Testing Features in Django 4.0

Django 4.0 had its first alpha release last week and the final release should be out in December. It contains an abundance of new features, which you can check out in the release notes. In this post we’ll look at the changes to testing in a bit more depth.

Read more...

Introducing django-upgrade, a tool for upgrading your Django projects

Django deprecates a small list of features with every feature release, requiring us to update our projects, which can be monotonous. Today I’m announcing a new tool I’ve created, django-upgrade, that automates some of this drudgery for us all.

Read more...

Django 3.2 Update for “Speed Up Your Django Tests” Released

I released my book “Speed Up Your Django Tests” over a year ago, in May 2020. Since then, we’ve seen two major Django releases, including a whole bunch of test-related changes, some of which I worked on as part of the book.

Read more...