Using uv to Manage Django Projects
uv
is a tool from Astral.sh that helps you manage Python tools and development projects. For all the details you can
read the docs, but here's a quick lesson in what it can do and how it can help Python developers in the daily grind of developing Python software. We'll walk through managing a hypothetical Django project.
Installing and/or Running Python Tools
Django has a command for starting new projects: django-admin startproject myproject
.
But of course, you have this chicken and egg problem. In order to start a Django project, you must first have Django installed. uv
's tool
subcommand fixes this problem. uv tool run
(and its shortcut alias, uvx
) will create a temporary virtual environment, install the requested tool into it, and run it from there.
So to bootstrap my Django project with uv
I can:
uvx --from django django-admin startproject myproject
The --from
tells uv
which package to install. You can leave that out if the package and the command have the same name.
If you don't already have Python installed, uv
can install it for you:
uv python …
Django Settings: Three Things Conflated
If you work on a large Django project, there's a good chance that you would describe your settings file as "a mess" (or perhaps you use harsher language). You may even have broken your settings out into a whole package with multiple files to try and keep things organized. We're highly skilled and organized developers, how does this happen to us?
I believe part of the problem is that the "settings" bucket holds three different kinds of things without differentiating between them. If you make a clear distinction between these things in your own mind (and in your code), dealing with settings will become easier, if not easy.
Project composition
The first class of settings comprises those used for project composition. One of the killer features of Django is that projects are composed of independent modules (apps). The most important settings in your project's settings file define what apps make up the project and how they interact with each other. In other frameworks this would be done with code (well, technically settings are Python code), but in Django this is treated as configuration. Things like INSTALLED_APPS, MIDDLEWARE_CLASSES, and TEMPLATE_CONTEXT_PROCESSORS define how the components of your …