Do you have a best-practices and coding style when developing with Jinja2?
Personally, I like the style in Plurk/Solace, but I'd like to know what other styles and practices people use when writing Jinja2.
Jinja2 is a modern day templating language for Python developers. It was made after Django's template. It is used to create HTML, XML or other markup formats that are returned to the user via an HTTP request. You can read more here.
In the past it was possible to generate templates from a string with the default environment configuration by using jinja. from_string . Jinja 2 provides a Template class that can be used to do the same, but with optional additional configuration.
Jinja is a web template engine for the Python programming language.
Chromium has a detailed Jinja style guide — I'm the original author, based on personal use, feedback from colleagues, and reviewing others' code.
Beyond Jinja-specific guidelines — mostly "keep it simple, since it's an unfamiliar DSL" and many tips — the subtlest question is how to structure the Python code, and the Python/Jinja interaction. Our main conclusions:
Jinja has powerful features, but most uses are pretty simple templates written by people who rarely use Jinja, so the goal is to put the text chunks and basic string processing in Jinja, but keep the complex logic in Python, which is better-suited and more familiar.
As a set of examples of Jinja2 styles, here's a list of projects using it:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With