Skip to content

v0.3.0

Choose a tag to compare

@MasonLyons MasonLyons released this 17 Oct 20:17
· 25 commits to main since this release

The body of a bridged block tag now renders natively. Tags like {% localtime %}, {% timezone %}, {% cache %}, simple_block_tag, and third-party block tags call parser.parse(), which used to compile their body with Django's own parser, so everything inside ran at stock speed. Now the body compiles on the Rust parser.

pip install -U django-rust-templates

Faster

  • Bridged block-tag bodies: wrapping a loop of aware dates in {% localtime on %} used to render at 1.0x. It now renders 13.1x faster than stock, and a simple_block_tag around a loop renders 14.5x faster. Compiling these templates went from 0.86x to 2–5x.

How it works

  • The tag's own Python code still runs unchanged. Only its parser.parse() call continues on the Rust parser.
  • The tag gets back a real NodeList. Calling render() renders the whole body natively. Inspecting it (get_nodes_by_type, iteration, len) sees stock-compatible nodes, and if a tag edits the list, it renders the edited list the stock way.
  • {% block %} and {% partialdef %} inside a bridged tag keep working, including block overrides through {% extends %}.

Known gaps

  • {% blocktranslate %}, {% static %} and humanize naturaltime are still Python.

Output stays byte-identical to stock Django. Django's template test suite passes 100% on 5.2 and 6.1.

Full change: #2