Recent Posts (Page 8)

Django: A security improvement coming to format_html()

Can you spot the problem with this Django snippet?

Read more...

“Boost Your Git DX” available in early access

I’m happy to announce that my new book, Boost Your Git DX is available now, in “early access”.

Read more...

Git: Detect an in-progress cherry-pick, merge, rebase, or revert

To detect if a certain operation is in progress in a Git repository, use git rev-parse like so:

Read more...

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:

Read more...

Django: Parametrized 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.

Read more...

How to download a documentation website with Wget

Sometimes you want to download a whole website so you have a local copy that you can browse offline. When programming, this is often useful for documentation that sites that do not provide downloadable versions, and are not available in offline tools like DevDocs.

Read more...

Django: How to profile and improve startup time

Your Django project’s startup time impacts how smooth it is to work with. Django has to restart your project every time you run a management command and when runserver reloads. This involves importing all your apps, and thus all the modules that they import.

Read more...

How to migrate from Django’s PostgreSQL CI Fields to use a case-insensitive collation

If you upgrade to Django 4.2, you may see system check warnings like:

Read more...

django-upgrade release with Django 4.2 fixers

I just released django-upgrade 1.13.0. The headline features are some new fixers targeting Django 4.2, which is currently in alpha.

Read more...

Git: How to skip hooks

Git hooks are useful for enforcing standards in your repositories. But sometimes, they’re in the way and you gotta skip ’em (locally), such as when writing “WIP” commits, experiments, and even testing hooks. Here are a few techniques for skipping hooks.

Read more...

pre-commit: How to create hooks for unsupported tools

The pre-commit framework lists hundreds of hook repositories on its hooks page. You can drop these into your configuration file and get a tool running in seconds. But there are many more tools out there that you might want to use, which you can run with custom configuration.

Read more...

New purchasing power parity discounts

Since shortly after the launch of my first book, I’ve offered a simple “purchasing power parity” deal: a 50% discount for those outside the top 50 countries by GDP (according to Wikipedia’s table). I really want to make sure my knowledge is accessible by as many people as possible, at a fair price.

Read more...

Git: How to add and remove execute permissions

POSIX permissions include the execute permission, which allows the file to be executed as a program. The permission can be set for each of the three classes: user, group, and others. So, for example, you can have a file that is executable only by its owning user.

Read more...

Tidelift for five packages I maintain

Since December, several of my open source packages have been “lifted” on Tidelift. This means that Tidelift are paying me a portion of their subscription fee for continued, standardized maintenance of these packages. These funds are very appreciated, so thanks to Tidelift subscribers 🫡.

Read more...

Git: How to change the case of filenames

Different filesystems have different case sensitivity, for example:

Read more...

Django settings patterns to avoid

Here are some potential mistakes made with Django settings that you can avoid.

Read more...

Django-related Deals for Black Friday and Cyber Monday 2022

Here are some Django-related deals for this year’s Black Friday (25th Nov) and Cyber Monday (28th Nov), including my own. For more deals on general Python-related products, see Trey Hunner’s post.

Read more...

Python: unittest’s new context methods from Python 3.11 (with backports)

Python 3.11 only made one change to unittest, but it’s a good one: context manager methods. These methods can simplify setup and teardown logic in many cases, such as dynamic use of unittest.mock.

Read more...

Git: How to disable status advice

Many Git commands output “advice”, with hints about which commands you could run next. Most notably, git status gives you advice for what to do about files in each state:

Read more...

Git: An alias to speed up fixing merge conflicts

There you are, minding your own business, rebasing your branch and… surprise! A merge conflict!

Read more...

Shell: search your virtualenv for mystery error messages

Sometimes error reporting loses details, and you don’t know where an error message comes from. In such cases, I have often found that the fastest way to track down the source is to search through the project and its virtualenv.

Read more...

pre-commit: How to run hooks during a rebase

pre-commit uses Git’s hook system to run tools when you commit. Unfortunately, Git doesn’t run any hooks when making a commit during a rebase. This can lead to you rebasing a branch and not realizing some code needs fixing, at least not until your CI system runs pre-commit (say, with pre-commit.ci).

Read more...

Git: How to set up a global ignore file

Have you ever accidentally committed a bunch of junk created by your OS, like Thumbs.db files from Windows, or .DS_Store files from macOS? Or, have you joined a project, and for one of your first commits, added rules to the .gitignore file for your text editor’s project files? If so, this post is for you! You can avoid such pain or busywork by making a global ignore file.

Read more...

Git: automatically stash while rebasing or merging with autostash

Imagine you’re part way through making some changes, and you realize that you need to rebase or merge. You can:

Read more...

Why does Python log a DeprecationWarning saying “invalid escape sequence”?

Take this code, which prints a shruggy man:

Read more...