[Answer]-Django template difference between {{ and {% with certain datas

1👍

Its because user.groups.all.0 is not string, but is Group object. So if you compare it to string then comparison fails. You should probably change it to

{% if user.groups.all.0.name == "Admin" %}

{% endif %}

And it does not fail (or raise error) when you print out {{ user.groups.all.0 }} because when you do something like this, then Class’s or object’s unicode method kicks in and prints out its name as string.

Leave a comment