Skip to content

start-django Docs

start-django.fly.dev ^3.11 4.2 + fly.io personal boilerplate, ft.:

  1. UI from django-fragments attempting locality-of-behavior:
    1. {% icon %} - <svg> tag combiner
    2. {% themer %} - <button onclick=toggleTheme()> enclosing two {% icon %}s.
    3. {% hput %} - TailwindCSS + widget-tweakable <input>
    4. {% sel %} - hyperscript w/ aria-* <select>
    5. {% include '_msg.html' ... %} - -htmx messages
  2. Deployable fly.toml based on compose.yml services:
    1. web: toggle settings: dev | test | prod
    2. db: sqlite default, postgres-configurable
    3. worker: huey background tasks
    4. redis: message broker
  3. Connected Custom User Model:
    1. django-allauth logic where UI templates have been styled.
    2. python-postmark transactional emails (e.g. confirm auth, change password, etc.)
    3. 1-to-1 Profile with ImageField (custom storage class to host/serve Cloudflare Images)
    4. foreign key UserConsent model for Terms of Use.
poetry, npm, vscode, just, ^3.11 python
# 'just' wraps initial setup into a single command
gh repo clone justmars/start-django dj \
  && cd dj \
  && just start # (1)
  1. When copy/pasting, just change dj to whatever folder. See to unpack steps in this recipe which includes virtual environment (.venv) setup via poetry; installation of tailwind with npm and running the build step with npx tailwindcss; and initial management commands: collectstatic, compress, makemigrations, migrate and runserver_plus (from django_extensions).
Setup using native commmands without 'just'; requires: poetry, npm, python ^3.11
gh repo clone justmars/start-django && cd start-django

cp ./etc/env.example.0.dev .env # (1)
npm install -D tailwindcss \
  @tailwindcss/typography \
  @tailwindcss/forms \
  @tailwindcss/aspect-ratio \
  @tailwindcss/container-queries # (2)

npx tailwindcss \
-i ./src/static/css/input.css \
-o ./src/static/css/output.css # (3)

poetry install && \
poetry export -f requirements.txt \
--without-hashes \
--output src/requirements.txt \
&& poetry shell # (4)

test -d src/data || mkdir src/data
cd src
python manage.py makemigrations # (5)
python manage.py migrate # (6)
python manage.py collectstatic --noinput # (7)
python manage.py compress --force # (8)

pre-commit autoupdate # ensure updated config
pre-commit run --all-files # applies: ruff, black, djhtml
pytest # will use pyproject.toml args

python manage.py runserver_plus # (9)
  1. Set example file to .env to make it easy to supply env vars.
  2. This will create /nodemodules/ (.gitignoreed) containing TailwindCSS dependencies.
  3. Invokes /src/static/css/input.css + ./tailwind.config.js to build /static/css/output.css. See full process
  4. Installs virtual environment in a local .venv (assumes poetry config --list shows virtualenvs.create = true and virtualenvs.in-project = true) then creates poetry.lock, ensures a copy of the requirements.txt file is copied into /src
  5. Prepares models declared in src/pages and /src/profiles as sql statements found in /migrations folder of each app. Since I didn't declare a DATABASE_URL in the environment, this will default to creating an empty src/db.sqlite
  6. Sets up tables in default sqlite database (unless a DATABASE_URL pointing to a local postgres db is set in .env)
  7. Populates /src/staticfiles directory
  8. Creates compressed css / js manifest in /src/static/CACHE
  9. Django management command to launch django.setup(). No need to setup .env values since default local settings will be used as a quickstart example. Uses django_extention's runserver_plus