Reputation: 127
I wanted to use try and except in djagno template is there is any way to use it.
I want to check either attendance table has any data of not. and if not it has to show error text
{% try %}
{% for attendances in attendance %}
....
{% endfor %}
{% except %}
<h1>Error Attendance table has no data.</h1>
Upvotes: 1
Views: 49
Reputation: 6565
Instead of try-catch, you can use Django's built-in for..empty template tag.
{% for attendances in attendance %}
....
{% empty %}
<h1>Error Attendance table has no data.</h1>
{% endfor %}
This will show the error message if the table is empty.
Upvotes: 2