How to add Conditional CSS class based on Python If statement

Robert picture Robert · May 9, 2017 · Viewed 9.1k times · Source

How do you add a conditional CSS class based on a Python if statement in the following example to show the has-success has-feedback form element?

<div class="form-group {% if not error_username %} has-success has-feedback {% endif %}">

Answer

SumanKalyan picture SumanKalyan · May 9, 2017

Write if condition this way.

<div class="form-group {{'has-success has-feedback' if not error_username }}">