Using uv for Django projects

uv can be used to bootstrap Python for a Django project on a machine with nothing else except uv installed.

Rough steps:

  1. Install uv. This is the trickiest bit but sets you up well for future projects.
  2. Create a Python project
  3. Add Django as a dependency to the project
  4. Run Django commands using uv (uv run django-admin or uv run python manage.py)

An example using the Django tutorial’s first steps:

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# If you need curl try `brew install curl or `apt-get install curl` or `yum install curl`

# Create a python project
uv init djangotutorial

# Go into the project folder
cd djangotutorial

# Add Django
uv add django

# Initialize a Django site
uv run django-admin startproject mysite .

# Run the site
uv run python manage.py runserver

# Go to http://localhost:8000/

Where the tutorial says python manage.py you can pretty much always use uv run python manage.py.

The other nice feature of this approach over the usual Django tutorial is you start out with a project Python project, ready to package and deploy.