Chromium has a detailed Jinja style guide - I am the author of the original, based on personal use, peer reviews and viewing others, code.
Aside from Jinjaβs special recommendations - basically, βkeep it simple because itβs an unfamiliar DSLβ and many tips - the subtlest question is how to structure your Python code and Python / Jinja interaction. Our main findings:
- Logic in Python (Python should go above a single line, keeping Jinja simple).
- One way flow: Python -> Jinja. Do not call Python from Jinja (other than custom filters) to avoid complexity.
- Define each context in one dictionary . This is your Python / Jinja interface, and is much easier to understand than building a dictionary in stages.
Jinja has powerful features, but most use fairly simple templates written by people who rarely use Jinja, so the goal is to put text snippets and basic string processing in Jinja, but preserve complex logic in Python, which is better-prepared and more familiar.
Nils von barth
source share