Django Quiz 2023
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.
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.
Some models have one or a few large fields that dominate their per-instance size. For example, take a minimal blog post model:
URLField.assume_scheme warningsSince Django’s inception, the web has gradually moved from HTTP to HTTPS, a welcome move for security. But the history has meant older parts of Django have had a lingering HTTP bias. Many of these have been migrated to default to HTTPS instead in previous versions. Django 5.0 starts the migration of another, tiny HTTP bias in forms.URLField.
git status output with --short or status.shortBy default git status uses “long format”, which lists information explicitly. This format takes quite a lot of words and vertical space to split file status by section:
git reflogIf you make a mistake whilst rebasing, it might seem hard to undo. But with git reflog, you can find the original commit SHA and revert back to it. Let’s see how with an example.
Here are some Django-related deals for this year’s Black Friday (24th Nov) and Cyber Monday (27th Nov), including my own.
runserver with lsofIf you start runserver but your terminal session gets closed, the server can continue running in the background. For example, this can happen when your IDE crashes. This situation is annoying because you can’t stop the backgrounded runserver with Ctrl-C.
Earlier this week, I made another podcast appearance on The Python Show, episode 22: Git and Django with Adam Johnson. As fellow authors, Mike and I talked a lot about the writing process, on topics like:
Last week, I made another podcast appearance on the PyBites Podcast, episode 139: Maximizing Your Developer Experience (DX) with Adam Johnson. We talked about various topics, including:
I had the pleasure of returning to The Real Python podcast in last week’s episode 179, Improving Your Git Developer Experience in Python. It was great to catch up with host Christopher Bailey and chat about:
Here’s a write-up of an optimization I made in my client Silvr’s project. I ended up disabling a PostgreSQL feature called the JIT (Just-In-Time) compiler which was taking a long time for little benefit.
git log with a commit SHA shows that commit and those before it:
Most projects I work on use Python, good ol’ Pip, and pip-tools. Below is a pattern I’ve used to speed up the GitHub Actions workflow runs on several such projects. On larger projects with many dependencies, it can save tens of seconds per run.
--force-with-lease and --force-if-includesWhen you push, Git checks that you are only adding commits to the remote branch. If you try to push an out-of-date branch, it will fail:
To show only the subject of the latest commit (the first line of its message), use:
The clipboard is an easy way to transfer data from the command line to other tools. Use your system’s “copy to clipboard” command to store a command’s output for pasting into other applications.
You worked on a sizeable feature branch some time ago but left it to focus on other things. Now you’re ready to pick it up, so you want to rebase it onto your updated main branch. But when you try that, you’re presented with an overwhelming number of merge conflicts.
I released Boost Your Git DX nearly two weeks ago. It’s the second in my “Boost Your DX” series, following last year’s Boost Your Django DX. Both books aim to improve your development experience with their respective tool.
My new book, Boost Your Git DX is out now, on my birthday 🥳. It’s taken nearly a year of work with four months in early access.
To show the initial, or root, commit* of your repository, use:
I’ve once more had the pleasure of joining Carlton and Will on the Django Chat podcast, in Episode #146. We spoke on Tuesday, just hours after Django 5.0 alpha 1 was released, on several topics:
.gitkeep files, use .gitignore insteadGit only tracks files, not directories. It will only create a directory if it contains a tracked file. But sometimes you need to “track” a directory, to ensure it exists for fresh clones of a repository. For example, you might need an output directory called build.
Django’s template engine has an underappreciated builtins option that selects libraries to preload in every template. Making a library a builtin avoids the need for an explicit {% load %} tag whenever you use its tags or filters. Putting key libraries in builtins can shorten your templates and make development a little bit faster.
The Python standard library’s logging module is a go-to for adding observability to applications. Many tools also integrated with it or enhance its capabilities, such as structlog and Sentry.
.git directoryEvery object you commit in Git is copied into its object store, within the .git directory. If you undo a commit, the commit object and associated file objects remain in Git’s object store, at least for a while. The normal garbage collection process will clean them out, by default in 30 days.