Django Static Files
Static files are application assets such as CSS and JavaScript. They are different from files uploaded by users and have a different trust and release lifecycle.
How it works
The project keeps its original stylesheet under static/workshops/site.css and references it with the static template tag. Namespacing asset paths prevents one app’s site.css from silently colliding with another’s. STATICFILES_DIRS identifies source locations while STATIC_ROOT is a collection destination. Do not place private uploads or database backups in either public asset tree. The lab’s source list shows which files belong to each role.
Run in the supplied local Django project
This lesson uses Django 5.2.18 LTS with Python 3.12. Download the source downloader and run node download-project.mjs http://127.0.0.1:8000 with Node 22 while previewing locally. It creates a new bhylu-django-lab folder and refuses to overwrite an existing one. After deployment, the default base is bhylu.com; until then use your local preview URL.
Inside that new folder, create a virtual environment, install requirements.txt and run the complete lesson file shown below. Every lesson creates a fresh in-memory SQLite database and temporary upload storage. It does not edit the interactive lab’s db.sqlite3 or Bhylu’s database. The visible listing below is the lesson’s core code; its complete downloaded file includes the shared bootstrap.
Django does not run in Bhylu’s current browser playground. No Apache, MySQL or global PHP configuration change is needed. See the setup lesson for the full project and commands.
Example
Run .venv\Scripts\python.exe lessons\static-files.py from the downloaded project root. Download the complete lesson file; keep it under lessons/. The project’s shared models, forms, views and fixture are prerequisites, not a hidden online runtime.
from django.contrib.staticfiles import finders
from django.templatetags.static import static
path = finders.find("workshops/site.css")
print(path is not None)
print(static("workshops/site.css"))
print("background" in open(path, encoding="utf-8").read())
Expected result
True /static/workshops/site.css True
The finder locates the authored source and the static helper builds its URL. This check does not mean runserver is a production static server. A separate collect-and-serve review checks the prepared WhiteNoise path.
Use Django’s versioned official documentation for exact API contracts and the deployment checklist before a separate release.