1

I am looping through leaves in which I want to print only those values where leave.status = null. I am unable to write jinja template for that.

{% for leave in leaves%}
            
              **<!-- if leave.status = null then show value else skip -->**

                <tr class="text-gray-700 dark:text-gray-400">
                    <td class="px-4 py-3">
                        <div class="flex items-center text-sm">
                            <!-- Avatar with inset shadow -->
                            <div >
                                <p class="font-semibold">{{leave.emp_id}}</p>
                                <p class="text-xs text-gray-600 dark:text-gray-400">
                                </p>
                            </div>
                        </div>
                        </td>
                        <td class="px-4 py-3 text-sm">
                            {{leave.TOL}}
                        </td>
                        <td class="px-4 py-3 text-sm">
                            {{leave.start_date}} to {{leave.end_date}}
                        </td>
                        <td class="px-4 py-3 text-sm">
                            {{leave.days}}
                        </td>
                        <td class="px-4 py-3 text-sm"> 
                          <button class="open-button" onclick="openForm()">Open Form</button>

                          {{leave.description}}
                        </td>
                        <td class="px-4 py-3 text-xs">
                            <a href="/approve/{{leave.emp_id}}"><button style="margin-right: 18px;" class="px-2 py-1 font-semibold leading-tight text-green-700 bg-green-100 rounded-full dark:bg-green-700 dark:text-green-100">
                              Approve
                          </button ></a>
                            <a href="/reject/{{leave.emp_id}}">
                              <button  class="px-2 py-1 font-semibold leading-tight text-orange-700 bg-orange-100 rounded-full dark:text-white dark:bg-orange-600">
                                &nbsp;&nbsp;Reject&nbsp;&nbsp;
                            </button >
                            </a>
                        </td>
                    </tr>
                    
            {% endfor %}
Klaus D.
  • 13,874
  • 5
  • 41
  • 48

2 Answers2

0

I dont see any if in your code

{% for leave in leaves%}
            
{% if leave.status == null %}
    Do something
{% else %}
    Do else
{% endif %}

{% enfor %}
Astros
  • 179
  • 1
  • 10
0

Use the "none" test as so:

{% if leave.status is none %}
leave.status is none
{% endif %}

Keep in mind that "none" is lower case so do not confuse it with pythons "None".

See also:

M_dk
  • 2,185
  • 1
  • 13
  • 15