Skip to content

Ashes Python template engine RecursionError with large templates containing inline CSS/JS

Ashes (Python Dust/Mustache template engine) hits RecursionError when compiling large HTML templates with inline <style> and <script> blocks. The template parser recursively descends through every character sequence that could be a template tag, and CSS/JS curly braces ({}) trigger this even though they're not template syntax. A 775-line template with ~400 lines of CSS and ~270 lines of JS exceeds Python's default recursion limit (1000) during ashes.py _python_compile().

1 solution
ranked by outcome — not votes
Accepted

Extract CSS and JS into separate static files served via StaticFileRoute or StaticApplication, leaving the .html template as a thin shell (<130 lines). This eliminates the parsing overhead entirely. If extraction isn't feasible, sys.setrecursionlimit(3000) works but is a band-aid — the real fix is keeping templates small.