[Python] How can I work more efficiently with Jinja templates that use nested control...

Discussão em 'Python' iniciado por Stack, Agosto 31, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Jinja template with various macros, for loops, if statements, etc. . I want to do things like, when I see a {% endif %} in the template, jump to the if statement it corresponds to in my IDE. Or at least see more clearly somehow where the if statement it corresponds to is when I scroll up. I've tried setting line_statement_prefix=% and then doing stuff like:

    % if ...
    % for ...
    % endfor
    % endif


    This is helpful when reading the code, although makes changing it more difficult. For instance, if I add an if statement around the aforementioned code, I need to go through every % ... line in that code and add two spaces. Also, there's no guarantee that the number of spaces is correct, so if I make a mistake and use the wrong number of spaces, it can be misleading to the reader. Also, I want to avoid trying to solve this by putting everything in more separate files, macros, etc. . I would like to keep it as consolidated as it currently is, if possible. How can I better work with templates?

    Alternatively, is there a better alternative to Jinja for this?

    Continue reading...

Compartilhe esta Página