bhylu.com

Advertisements

Django collectstatic

collectstatic gathers application assets into STATIC_ROOT. It is a Django lab operation and is separate from exporting or publishing the Bhylu website.

How it works

Use a fresh temporary collection destination for review so no existing site files can be overwritten. The command can gather admin assets as well as the project’s own stylesheet. This lesson checks the copied file, not just the command’s exit code. A production workflow should also choose cache and storage behaviour deliberately. Do not run collectstatic into Laravel public, the Bhylu publishing folder or an upload directory.

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\collect-static.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.

lessons/collect-static.py — core code

from pathlib import Path
from tempfile import TemporaryDirectory
from django.core.management import call_command
with TemporaryDirectory(prefix="django-static-") as folder:
    with override_settings(STATIC_ROOT=folder):
        call_command("collectstatic", verbosity=0, interactive=False)
    print((Path(folder) / "workshops/site.css").is_file())
    print((Path(folder) / "admin/css/base.css").is_file())

Expected result

True
True

Both the original stylesheet and a Django admin asset reach the temporary collection tree. The directory is owned by the lesson and is removed when the context exits. No website export or deployment occurs.

Use Django’s versioned official documentation for exact API contracts and the deployment checklist before a separate release.

Advertisements