🚀 I have just released a major update to my 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.
Django applications are used to run Antarctic expeditions, energy distribution, logistics chains, and the World Food Program.
The JPEG sharing site Instagram is cool but there are so many more uses!
🕺 From
#Python
3.13, virtual environments created by `venv` will come with a Git ignore file, thanks to
@brettsky
’s PR merged yesterday. There’ll be no need to add `.venv` (or whatever) to your `.gitignore` file then.
Yesterday I updated my open source projects so that successive pushes to a PR cancel prior CI runs. Saves some time and processing power.
I found the "how to" kinda hidden in the docs:
🎨 Did you know? From Django 4.1, code generated by Django (startproject, makemigrations, etc.) will be formatted by Black - just like the Django code base.
Version 21.10b0 of Black, your friendly
#Python
auto-formatter, is out now! 🖤
The biggest news is that thanks to
@pradyunsg
and
@jelleszijlstra
we adopted a stability policy that will go into effect starting with the first stable release in Jan 2022. 🤯
🎺📦 New package: django-browser-reload 📦🎺
It does what it says on the tin: in development it autmoatically refreshes your site when you make a change to a template or code.
No more pounding “refresh”!
🆙 Happy Sunday. I've just updated a bunch of my packages to support Django 4.1 (which is in Alpha) and Python 3.11 (which is in beta):
* django-auto-prefetch
* django-browser-reload
* django-cors-headers
* django-htmx
* django-linear-migrations
* django-mysql
...
@willmcgugan
My pacakage patchy lets you live-patch functions to change what they do. Useful for applying small changes to third party dependencies without forking.
✍️ ”I'm delighted to announce my new e-book, coming May 18...
Speed Up Your Django Tests!
It's a practical guide to making your
#Django
project's tests faster...”
@activefog
@thefinaldownco
@PrasoonPratham
The problem is using the shared, predictable random instance. If some other piece of code (e.g. a library you installed), calls random.seed(0), then your passwords will be the same every time.
📦 New package: django-minify-html 📦
This provides a Django middleware for running minify-html, the “extremely fast and smart HTML + JS + CSS minifier”. It minifies HTML, and any inline JS and CSS, with little overhead.
✨Just released django-rich 1.2.0 with a new Rich-based test runner thanks to
@David_Smith86
! ✨
This gives Django’s test framework a nice lick of paint and useful features like expanded tracebacks with locals and clickable source links.
Check it out:
✍️ When I started writing type hints, I was a little confused about what to do with Python’s variable argument operators, * and ** (often called *args and **kwargs). Here’s what I figured out.
🥳 Boost Your Git DX is out! 🥳
📕 353 pages across 18 chapters on improving your
#Git
command line development experience.
💁 It covers the best tools, techniques, tips, tricks, and tactical tidbits that I’ve encountered in 11 years of using Git.
🤖 Here's a simple view for serving a robots.txt from
#Django
.
See my tutorial for how this works, an alternative implementation with a template, and tests:
✍️ Using the phrase "of course" is condescending when you're explaining something, as it implies the reader should have already figured this out.
I've just made a PR to remove its usage from the
#Django
docs.
@activefog
@thefinaldownco
@PrasoonPratham
Moreover the default seed is the current time. If I know the algorithm and that the hour the password was generated, I can just test, say, the first 100 passwords for each of the 3600 seconds in the last hour, which is ~10^5 options rather than ~10^63 as the code intends.
In
#Django
5.1, test client methods will have a new query_params parameter to simplify adding URL query parameters.
Thanks to Tom Carrick for the PR,
@carlton
, David Sanders and
@felixxm
for reviewing, and everyone who participated in the forum discussion.
✍️ “I recently upgraded my client to PostgreSQL 13... I reindexed all tables after the upgrade to take advantage of this [new] deduplication and saw index storage savings of up to 90%.“
🚀
@MariuszFelisiak
just merged the database-generated fields commit into the upcoming Django 5.0.
Generated fields are computed by the database from other field values. They’re useful for shortening lookups, and even speeding them up if indexed.
🐍🧵 For custom classes, Python normally backs instances with a dictionary. But if you declare __slots__ on a Python class, it can use a more efficient representation, at the cost of disallowing arbitrary extra attributes.
🕰 If your project uses freezegun to mock datetime, move to my library time-machine to speed up your tests. It has a similar API but it's 100x faster, or more.
It's O(1) rather than O(len(sys.modules)) !
🧹 Clean up old, not-running Docker resources with this one-liner:
docker system prune --all --force --filter until=24h && docker volume prune --force
This command can save you a lot of disk space, I just used it to reclaim 38GB!
✍️ “The Boolean Trap” is a programming anti-pattern where a boolean argument switches behaviour, leading to confusion. In this post we’ll look at the trap in more detail, and several ways to avoid it in Python, with added safety from type hints.
Normally I develop just against localhost, but sometimes you need a real hostname to trigger particular web features. You can use for this, e.g. redirects to localhost:8000 .
🔮 Useful new feature just committed, coming in Django 4.2: robust on_commit() callbacks
on_commit(..., robust=True) will mean that if the callback fails, its exception is caught and logged, and other callbacks will also run.
e.g. trying to send two types of notification:
👏👏👏 Congratulations to fellow
@djangolondon
organizer
@cagilulusahin
for her first code contribution to Django core.
It fixes something that's bothered me for a while - migrations altering columns when only Python-level metadata has changed.
Flight attendant: Is there a Dr. on this flight?
Dad: *nudging me* that should've been you
Me: Not now Dad
Dad: Not looking for a Pythonista are they?
Me: Dad, there’s an emergency
Dad: Go and see if using "python -m pip install" instead of "pip install" will help
🚨 PyPI Phishing Attack 🚨
Two hours ago, I received the below email from a Mailchimp account - it's a phishing attack attempting to steal PyPI credentials. I happened to check my "spam" just now and find it.
#4
Built-in Redis cache backend
@Redisinc
is very popular with Django developers. Previously it was mainly used via the django-redis package, but now it’s built-in!
Thanks to
@Abbasidaniyal_
for contributing this as a Google of Summer of Code project.
♦️oh-my-zsh just got some new Git aliases!
🎋 gbm = git branch --move, to rename a branch
⏪ grhk = git reset --keep, to reset without throwing out uncommitted changes
⏪ grhs = git reset --soft, to reset without changing files, effectievly “undoing” commits
...
I just wrote this proposal that
#Django
’s third-party package tutorial recommend using a `django_` module prefix to prevent name collisions, such as the historical one between django-ratelimit and ratelimit.
What do you think?