[Fixed]-Django skip entry when looping over queryset (in template)

0👍

If you need to do this sort of editing then it isn’t working perfectly, you should filter these entries out of your queryset inside of your view

.exclude(var1="mystring")

In the comments you state that the queryset comes from an iterable, so at the very least you’d be able to do list comprehension in the view

[i for i in queryset if i.var1 != "mystring"]

If this is something you absolutely have to do in a template, then the only way is with the complete surrounding if statement that you already have in your question

👤Sayse

1👍

this may help you

{% if i.var1 != "mystring" %}

this simply skip mystring and loop counter also increase

👤mayur

Leave a comment