Format Jinja2 HTML templates with djLint and Prettier
I like to lint and autoformat. For HTML with Jinja2 templating, djlint and prettier are great, but they disagree on some details like long lines. Here's how I've been combining them:
I like to lint and autoformat. For HTML with Jinja2 templating, djlint and prettier are great, but they disagree on some details like long lines. Here's how I've been combining them:
Django's default date and time formats, from django.conf.locale.en.formats, reflect
its Lawrence, Kansas roots:
| Name | Django Format String | Sample | Comments |
|---|---|---|---|
DATE_FORMAT |
N j, Y |
April 29, 2026 |
Unambiguous, no time zone, months are language-specific, width varies |
SHORT_DATE_FORMAT |
m/d/Y |
04/29/2026 |
Ambiguous, no time zone |
TIME_FORMAT |
P |
2:30 p.m. |
Unambiguous, no time zone, slightly verbose, width varies |
DATETIME_FORMAT |
N j, Y, P |
April 29, 2026, 2:30 p.m. |
Combine above |
SHORT_DATETIME_FORMAT |
m/d/Y P |
04/29/2026 2:30 p.m. |
Combine above |
The target is RFC 3339, a profile
of ISO 8601 that uses a space between date
and time instead of the T separator. The space is easier to read: 2026-04-29 14:30 Z
vs 2026-04-29T14:30:00Z. With globalized settings:
| Name | Django Format String | Sample |
|---|---|---|
DATE_FORMAT |
Y-m-d \Z |
2026-04-29 Z |
SHORT_DATE_FORMAT |
Y-m-d \Z |
2026-04-29 Z |
TIME_FORMAT |
H:i \Z |
14:30 Z |
DATETIME_FORMAT |
Y-m-d H:i \Z |
2026-04-29 14:30 Z |
SHORT_DATETIME_FORMAT |
Y-m-d H:i \Z |
2026-04-29 14:30 Z |
Putting a timezone on a bare date is basically unheard of. But consider two people looking at the same date string:
| Viewer | Offset | Their interpretation | UTC span |
|---|---|---|---|
| Reader in California (PDT) | UTC-7 | Apr 29, midnight to midnight Pacific | 2026-04-29T07:00Z to 2026-04-30T06:59Z |
| Writer in India (IST) | UTC+5:30 | Apr 29, midnight to midnight IST | 2026-04-28T18:30Z to 2026-04-29T18:29Z |
Their interpretations differ by 12 hours 30 minutes. In the worst case--a UTC-12 reader and a UTC+14 writer--the same date spans a 50-hour ambiguity window.
Writing America/Los_Angeles or EST5EDT next to every date would be
unwieldy. But Z--two characters including the space--tells the reader this
date is UTC, narrowing the ambiguity window from 50 hours to 24. For internal
systems that already run on UTC, the burden is zero.
This is globalization: one format, everywhere, no locale adaptation.
Django's USE_I18N setting controls string translation, not date formatting. The setting
that controls whether formats adapt to the user's locale was historically USE_L10N, for
"localization." Django 5.0 removed USE_L10N. The replacement is FORMAT_MODULE_PATH.
Here is how to configure RFC 3339 datetimes across Django versions.
Display datetimes like 2026-04-29 14:30 Z everywhere:
Z timezone suffixSet USE_L10N = False. Django then uses the format strings from config/settings.py directly,
without consulting locale modules. USE_L10N is
deprecated in 4.x
but still works.
These are Python strftime format strings. The Z is a literal character.
USE_L10N is removed. The settings-level DATETIME_FORMAT strings are ignored because
Django's built-in locale formats take priority -- even with USE_I18N = False.
Django resolves format strings by checking modules in FORMAT_MODULE_PATH before falling
back to the built-in django.conf.locale.en.formats. We register our own module to override
the defaults.
Create a format module at config/formats/z/formats.py:
Format modules use Django's own template-tag format syntax, not Python strftime.
The equivalent of %Y-%m-%d %H:%M Z is Y-m-d H:i \Z (backslash-escaped Z literal).
Point Django at the module:
When code calls formats.get_format('DATETIME_FORMAT'), Django follows this path:
get_format_modules()FORMAT_MODULE_PATH first, then built-in locale modulesconfig/settings.pyWith FORMAT_MODULE_PATH = 'config.formats', our module is checked before
django.conf.locale.en.formats, so our RFC 3339 format wins.
USE_I18N controls Django's translation machinery of gettext, {% translate %},
language-prefixed URLs, and so on. It does not control date formatting. You can set
USE_I18N = True (to translate strings) while still using RFC 3339 datetimes via
FORMAT_MODULE_PATH. The two are independent.
Setting USE_I18N = False is still useful: it avoids loading translation catalogs at
startup and prevents Django from looking for locale-specific format modules that do not
exist. It also shuts off the admin's language-preference UI.
gh auth login does more than GitHub API access; it also configures git's credential helper.
From then on, HTTPS remotes authenticate as whichever account is active in gh.
Behind the scenes, gh registers itself as the credential helper:
When git needs credentials, it calls gh auth git-credential, which reads the stored token.
Token storage depends on the platform:
osxkeychain, the Keychain Access app~/.config/gh/hosts.yml (encrypted with a key from pass, gpg, or plain file)gh auth status confirms which account is active:
No SSH keys needed, no ~/.ssh/config. Every push authenticates as the
active gh account.
In GitHub Actions, GITHUB_TOKEN is available automatically via OIDC. When $GITHUB_TOKEN
is set, gh auth git-credential uses it instead of a stored token; no gh auth login
needed in CI. This is the same token that actions/checkout uses for HTTPS clones.
Pip and uv support git+https:// dependencies. There are two ways to authenticate them:
Token-in-URL works everywhere but risks leaking into lock files; older versions of uv and
pip-compile could bake the token into requirements.txt. With gh auth git-credential,
the URL stays concise and the credential helper handles auth transparently; git, pip,
and uv all use it. This requires gh installed in CI.
The fretboard post ended with βthese approaches also apply to musical staves.β This version does just that, but keeps one constraint: start with the Unicode staff glyph, measure the source units once, and derive the placement grid from those measurements instead of nudging pixels by hand.
The relevant character is 𝄚,
U+1D11A MUSICAL SYMBOL FIVE-LINE STAFF.
The source file in notofonts/music is
sources/NotoMusic.glyphs.
A small Python script now builds one measurement table across the 4-string fretboard, 5-string
fretboard, 5-line staff, stemless notehead, quarter note, and half note.
Minimal Python to download the source and print the table:
The full table is longer, but for this post the staff, quarter-note, and half-note rows are the ones that matter:
| Glyph | Codepoint | Glyph name | Advance | Bounds (l,b)-(r,t) |
Size | Center | Details |
|---|---|---|---|---|---|---|---|
| 5-line staff | U+1D11A | u1D11A |
1100 | (50, 0)-(1050, 1000) | 1000x1000 | (550.0, 500.0) | 5 lines; thickness 24; gap 220; center step 244; note step 122 |
| Quarter note | U+1D15F | u1D15F |
400 | (51, 11)-(350, 1009) | 299x998 | (200.5, 510.0) | measured from built TTF glyph bounds |
| Half note | U+1D15E | u1D15E |
397 | (50, -1)-(347, 1009) | 297x1010 | (198.5, 504.0) | measured from built TTF glyph bounds |
The useful CSS variables fall straight out of those measurements:
50 / 1000 is the left inset, 12 / 1000 is the top-line center, and 122 / 1000 is half of
the 244 unit line-center spacing, so it lands on both lines and spaces.
For the marks themselves, quarter notes and half notes are easier to read than bare noteheads. The
overlay uses Noto Music glyphs for both from the same musical-symbol family:
π
, U+1D15F MUSICAL SYMBOL QUARTER NOTE, and
π
, U+1D15E MUSICAL SYMBOL HALF NOTE.
With that grid, a sparse data-pos overlay can treat one scaled staff glyph as one 16-slot
measure block and place the treble clef, the stacked 4/4, and then the note characters. Every
character uses exactly one row letter plus a two-digit base-10 column: the clef centers on G,
column 02 is left empty because the treble clef is wide, the time-signature digits sit on a
and c, and the notes use their pitch rows. The last two digits give the column from 01
through 16. Uppercase and lowercase distinguish lower and
higher pitches. The first measure of βTwinkle, Twinkle, Little Starβ is G G d d; the next
measure starts a new staff block when the 16 slots run out.
This is the part I wanted from the start: one Unicode background glyph, one measured grid, and then ordinary markup on top. The fretboard glyph and the staff glyph both work better once the source units become the API.
Two mountain songs work well with the same three open chords. This version keeps both in G, so a
group can stay on G, C, and D7 all the way through.
Try β ββ βββ all the way through, or just keep a steady down-strum if the room is loud.
βββ―β―β―βThe bear went oβββ―β―β―βver theββββ―ββ―moun-βββ―β―β―βtain
βββ―β―β―βThe bear went oβββ―β―β―βver theββββ―ββ―moun-βββ―β―β―βtain
βββ―β―β―βThe bear went oβββ―β―β―βver theββββ―ββ―moun-βββ―β―β―βtain
βββ―β―β―βTo seeβββ―βββwhat heβββ―β―β―βcouldβββ―β―β―βsee
βββ―β―β―βAnd allβββ―βββthat heβββ―β―β―βcouldβββ―β―β―βsee
βββ―β―β―βAnd allβββ―βββthat heβββ―β―β―βcouldβββ―β―β―βsee
βββ―β―β―βAnd allβββ―βββthat heβββ―β―β―βcouldβββ―β―β―βsee
βββ―β―β―βWas theβββ―β―β―βother sideβββ―βββof theβββ―β―β―βmoun-tain
βββ―β―β―βShe'll be comβββ―β―β―βing'round theββββ―ββ―moun-βββ―β―β―βtainβββ―βββwhen sheβββ―β―β―βcomes
βββ―β―β―βShe'll be comβββ―β―β―βing'round theββββ―ββ―moun-βββ―β―β―βtainβββ―βββwhen sheβββ―β―β―βcomes
βββ―β―β―βShe'll be comβββ―β―β―βing'round theββββ―ββ―moun-βββ―β―β―βtain
βββ―β―β―βShe'll be comβββ―β―β―βing'round theββββ―ββ―moun-βββ―β―β―βtain
βββ―β―β―βShe'll be comβββ―β―β―βing'round theββββ―ββ―moun-βββ―β―β―βtainβββ―βββwhen sheβββ―β―β―βcomes
If you want a little more motion, hold D7 on the last cell, then turn back to G as the next
line starts.
The last post walked through ASCII art, CSS grids, sparse position markup, and the Unicode fretboard glyph. For a full seasonal song, this version uses the glyph-and-position approach with build-time templating, so concise source expands into a somewhat verbose HTML page.
In G:
Try one of these 4/4 strumming patterns:
β ββ ββββ β ββ βββββ―β―β―βChrist the Lord isββββ―ββ―risen to day-βββ―β―β―βay, a-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
ββββ―ββ―Sons of men andββ―ββββ―angelsβββ―β―β―βsay-βββ―βββayβββ―β―β―β, a-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
βββ―βββRaise your joys andβββ―β―β―βtry-βββ―βββumphs,βββ―β―β―βhigh,βββ―βββa-ββββ―ββ―al-ββββ―ββ―le-βββ―βββlu-ββββ―ββ―u-βββ―β―β―βia!
βββ―β―β―βSing, ye heavens, andββββ―ββ―earth re-ply-βββ―β―β―βy, a-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
βββ―β―β―βLives again ourββββ―ββ―glorious Ki-βββ―β―β―βing, a-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
ββββ―ββ―Where, O death, isββ―ββββ―now thyβββ―β―β―βsti-βββ―βββing?βββ―β―β―βA-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
βββ―βββOnce He died ourβββ―β―β―βsoulsβββ―βββtoβββ―β―β―βsave,βββ―βββa-ββββ―ββ―al-ββββ―ββ―le-βββ―βββlu-ββββ―ββ―u-βββ―β―β―βia!
βββ―β―β―βWhere thy victory,ββββ―ββ―Oβββ―β―β―βgrave? a-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
βββ―β―β―βLove's redeemingββββ―ββ―work isβββ―β―β―βdone, a-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
ββββ―ββ―Fought the fight, theββ―ββββ―battleβββ―β―β―βwon-βββ―βββon, a-βββ―β―β―βal-βββ―β―β―βle-ββββ―ββ―lu-βββ―β―β―βu-βββ―βββia!βββ―β―β―β
βββ―βββDeath in vain forβββ―β―β―βbidsβββ―βββHimβββ―β―β―βrise,βββ―βββa-ββββ―ββ―al-ββββ―ββ―le-βββ―βββlu-ββββ―ββ―u-βββ―β―β―βia!
βββ―β―β―βChrist hath openedββββ―ββ―paraβββ―β―β―βdise, a-ββββ―ββ―al-ββββ―ββ―le-βββ―β―β―βlu-βββ―βββu-βββ―β―β―βia!
For hymn background, this United Methodist Church history note is a good companion to the lead sheet.
The first line in the source looks like this:
That expands at build time into HTML like this:
Happy Easter!
Unicode includes an empty four-string fretboard, 𝄝, for ukulele or bass, and an empty six-string fretboard, 𝄜, for guitar. How are people supposed to compose the fretboard background and marks like β, β―, and β?
Going all the way back to ASCII art and box drawings, one approach is multiple lines: one column
per string, one row per fret, top markers for muted and open strings, and filled dots where
fingers land.
The canonical left-to-right order for guitars is L, E, A, D, G, B, e, R.
Open C major: x32010
E A D G B e β β― β― βββββ¬ββββ¬ββββ¬ββββ¬ββββ 1 β β β β β β βββββΌββββΌββββΌββββΌββββ€ 2 β β β β β β βββββΌββββΌββββΌββββΌββββ€ 3 β β β β β β βββββΌββββΌββββΌββββΌββββ€ 4 β β β β β β βββββ΄ββββ΄ββββ΄ββββ΄ββββ
This needed a pre tag with a tuned line-height to reduce the vertical gaps.
A CSS grid diagram looks like this:
A sparse data-pos version can skip the empty cells. The CSS ^= selector matches the starting
string letter, and $= matches the ending row number, so A3 decodes to the A string and third
fret. The string letters are supplemented with L and R for the margins, and the row numbers
with H for the header row and 0 for the nut marker row, which holds β and β―.
A Unicode-fretboard variation can keep the sparse data-pos markup and place marks from the
Noto Music source geometry. The six-string and four-string glyphs sit on the same integer grid:
a 37 unit stroke, a 135 unit gap, and 172 unit center spacing in a 1000 units-per-em font.
These approaches also apply to musical staves.
A barn quilt fiddle widget.
Each square carries four triangles in west (W), north (N), south (S), east (E) order.
Each triangle cycles through background, foreground, and accent.
Positions run A01 through Z99.
= Equals Value Logging= Equals ValueWide key=value logging keeps information explicit, compact, and searchable.
It uses named fields for most values; free-form text can still go on the right-hand side of
msg=. It also avoids the complexity and visual noise of JavaScript Object Notation (JSON).
Labeled Tab Separated Values (LTSV) keeps the same
wide, one-line shape while using : colon and \t tab separators instead of = equals and space. Brandur wrote
about logfmt in 2013: stable keys, small values, one request or task
per line. Another description I've
thought is appropriate for this format is "Wide INI (WINI)". In grep, journalctl, or Papertrail, searching for st=5
catches status codes 500..599 inclusive--with no parser in the loop. The Python structlog library exposes
KV renderer
and logfmt
for this style directly, and so does
python-logfmter.
| Format | Published | Structured | Key/Value | Element | Visually Noisy |
|---|---|---|---|---|---|
| Prose | No β | None β | \n newline β |
No β | |
| INInitialization (INI) | 1980s | Yes β | = equals β
|
\n newline β |
No β |
| Common Log Format (CLF) | 1995 | No β | None β | space β
|
π€· |
| YAML Ain't Markup Language (YAML) | 2001 | Yes β | : colon β
|
\n newline plus indentation β |
No β |
| JavaScript Object Notation (JSON) | 2001 | Yes β | : colon β
|
, comma β
|
Yes β |
| Labeled Tab-Separated Values (LTSV) | 2012 | Yes β | : colon β
|
\t tab β
|
No β |
| Tom's Obvious Markup Language (TOML) | 2013 | Yes β | = equals β
|
\n newline β |
No β |
| logfmt | 2013 | Yes β | = equals β
|
space β
|
No β |
Emit keys consistently to implement structured key=value logging. Most
operational values are simple scalars. Serialize iterables and mappings compactly to remain simple:
list=1,2,3 dict=1..2:buckle-my-shoe,3..4:knock-at-the-door. This follows the LTSV guidance of avoiding quotes and escapes to keep tooling requirements minimal.
As an escape hatch, complex data can be stuffed into the value as Python literals or JSON.
Reducing unnecessary punctuation also reduces LLM token usage.
Fewer lines are better, with one line per request (or task) as the ideal.
Canonical log lines makes that operational case well:
coherent context, easier streaming, and cleaner copy-paste to record incident details.
Multiple lines per request (or task) make key consistency harder to maintain.
LoggingSucks reaches the same practical conclusion from another
angle: wide single-line records make debugging and operations efficient, although Boris Tane's
unexplained choice of JSON over key=value adds punctuation and tool requirements
where clarity should win.
An aspiration here is to combine Gunicorn and Django output into one consistent wide
key=value log line.
In the meantime, here is an example of configuring gunicorn
with abbreviated keys:
Of course, abbreviating has downsides, so use whole words when they are a better choice or when you are unsure.
| Abbr | LTSV Recommend | Description | Apache | nginx | gunicorn |
|---|---|---|---|---|---|
time |
Time the request was received | %t |
$time_local |
%(t)s |
|
lb or ip* |
host |
Nearest client IP | %h |
$remote_addr |
%(h)s |
ff or ip* |
forwardedfor |
Forwarded client IP | %{X-Forwarded-For}i |
$http_x_forwarded_for |
%({x-forwarded-for}i)s |
us |
user |
Remote user | %u |
$remote_user |
%(u)s |
em |
User email | ||||
req |
First line of request (method, uri, rows) | %r |
$request |
%(r)s |
|
method |
Request method | %m |
$request_method |
%(m)s |
|
uri |
Request URI | %U%q |
$request_uri |
%(U)s%(q)s |
|
protocol |
Requested Protocol (usually "HTTP/1.0" or "HTTP/1.1") | %H |
$server_protocol |
%(H)s |
|
st |
status |
Status code | %>s |
$status |
%(s)s |
size |
Size of response in bytes, excluding HTTP headers; suffix with b for explicit units |
%Bb (or %bb for compatibility with combined format) |
${body_bytes_sent}b |
%(B)sb |
|
reqsize |
Bytes received, including request and headers; suffix with b for explicit units |
%Ib (mod_log_io required) |
${request_length}b |
%({content-length}i)sb |
|
rf |
referer |
Referer header | %{Referer}i |
$http_referer |
%(f)s |
ua |
ua |
User-Agent header | %{User-agent}i |
$http_user_agent |
%(a)s |
hs |
vhost |
Host header | %{Host}i |
$host |
%({host}i)s |
reqtime_microsec |
The time taken to serve the request, in microseconds; suffix with us for explicit units |
%Dus |
%(D)sus |
||
rt |
reqtime |
The time taken to serve the request, in seconds; suffix with s for explicit units |
%Ts |
${request_time}s |
%(L)ss |
cache |
X-Cache header | %{X-Cache}o |
$upstream_http_x_cache |
%({x-cache}o)s |
|
runtime |
Execution time for processing some request, e.g. X-Runtime header for application server or processing time of SQL for DB server. | %{X-Runtime}o |
$upstream_http_x_runtime |
%({x-runtime}o)s |
|
apptime |
Response time from the upstream server | $upstream_response_time |
* Replace lb or ff with ip based on presence or absence of load balancer.