Search code examples
pythonjinja2

How to Negate in this Jinja if condition?


I have this in template:

{% if cell %}{% set cell = "b" %}{% endif %}

What is contradiction of above conditional?

This not works:

{% if !cell %}

Solution

  • You might use not word, consider following simple example

    import jinja2
    template = jinja2.Template('cell {% if not cell %}negated{% endif %}')
    print(template.render(cell=True))  # cell 
    print(template.render(cell=False))  # cell negated