Recent Posts (Page 15)

Entering a Flaky Context Manager in Python

Here’s a little Python problem I encountered recently.

Read more...

How to use PyMySQL with Django

Django provides MySQL and MariaDB support out of the box. It supports the mysqlclient library as its DB API driver to connect.

Read more...

Common Issues Using Celery (And Other Task Queues)

Here are some issues I’ve seen crop up several times in Django projects using Celery. They probably apply with other task queues, I simply haven’t used them so much.

Read more...

Scoring A+ for SSL Labs on My Cloudfront-Hosted Static Website

I previously covered how I scored A+ for security headers on my site, which uses AWS CloudFront. I didn’t touch on scoring A+ for your TLS configuration though.

Read more...

Git: compare generated files before and after changes with git diff

Once in a while, I have to make a change to many or all of my blog posts. For example, implementing opengraph meta tags.

Read more...

Moving to Django 3.0’s Field.choices Enumeration Types

One of the headline features of Django 3.0 is its Enumerations for model field choices. They’re a nicer way of defining and constraining model Field.choices.

Read more...

Django’s Field Choices Don’t Constrain Your Data

This post is a PSA on the somewhat unintuitive way Field.choices works in Django.

Read more...

Python: fix SyntaxWarning: "is" with a literal

Take this reasonable-looking code:

Read more...

Django Quiz 4

On Wednesday evening last week I held a quiz at the January London Django Meetup Group. This was the fourth quiz, which has become an annual Christmas tradition at the meetup. Unfortunately it was a month late this year due to venue changes, so I’ve titled this post “Django Quiz 4”.

Read more...

A Git Check for Missing Commits From a Remote

I recently add a pre-flight check to a devops project to ensure that all commits from the Git repository’s origin/master are present locally. This is to guard against developers accidentally reverting others’ deployed changes.

Read more...

Simplify Your If Statements That Return Booleans

Here’s a hint I have found myself repeating in code review. I learnt this from my university lecturer Tony Field, who probably repeated it in every lecture! He was teaching us Haskell, but it applies to Python, and most other programming languages.

Read more...

Make Django Tests Always Rebuild the Database if It Exists

If you use Django’s test runner, you’ll probably have encountered this message:

Read more...

Feature Checking versus Version Checking

Bruno Oliveira, known for his work on the pytest project, tweeted this thread last July:

Read more...

My Most Used pytest Commandline Flags

pytest is quickly becoming the “standard” Python testing framework. However it can be overwhelming to new users.

Read more...

Limit Your Try Clauses in Python

Take this code:

Read more...

Word Counting My Whole Site

My site is static HTML, built with Jekyll (more details in my colophon). This means I have a folder that contains the whole site in HTML files.

Read more...

Losslessly Compressing My JPEG Photos with jpegoptim

I’ve recently been running low on disk space on my laptop. I’ve freed some by removing files, but I’ve also been looking for ways to save space through compression.

Read more...

Working Around Memory Leaks in Your Django Application

Several large Django applications that I’ve worked on ended up with memory leaks at some point. The Python processes slowly increased their memory consumption until crashing. Not fun. Even with automatic restart of the process, there was still some downtime.

Read more...

A Single File Asynchronous Django Application

Django 3.0 alpha 1 came out this week. It introduces ASGI support thanks to lots of hard work by Andrew Godwin.

Read more...

Python: how I import the datetime module

Python’s datetime module risks a whole bunch of name confusion:

Read more...

Adding EC2 Instance Recovery Alarms with CloudFormation

Instance Recovery is a little-advertised, little-used feature of EC2. It doesn’t take long to set up and promises to recover your instance on the rare occasion that the underlying hardware fails. Recovery resumes the instance on new hardware, retaining its instance ID, private IP addresses, Elastic IP addresses, and all instance metadata.

Read more...

Jef Raskin on Why Software Is the Way It Is

I was reading 37signals’ Getting Real the other morning, and was struck by this quote in the chapter Embrace Constraints:

Read more...

My Appearance on DjangoChat

A few weeks ago I had the pleasure of talking over the internet with Will Vincent and Carlton Gibson about lots of Django-related topics. They somewhat informed me it was being recorded for a podcast.

Read more...

A Minimum Viable CloudFormation Template

Sometimes when testing CloudFormation features I need a minimum viable template to try that feature with.

Read more...

How to Add Database Modifications Beyond Migrations to Your Django Project

On several Django projects I’ve worked on, there has been a requirement for performing database modifications beyond Django migrations. For example:

Read more...