[Django]-Django: if in list template tag

5👍

You can try to create an “In” filter by your self.

# Somewhere in your template filters and tags

@register.filter
def InList(value, list_):
  return value in list_.split(',)

and in your template:

{% load inlist %}

{% if not '1'|InList:'5,6,7,8,9,10,11,12,13' %}
<div>1 is not inside</div>
{% endif %}

{% if '5'|InList:'5,6,7,8,9,10,11,12,13' %}
<div>5 is inside</div>
{% endif %}

I’ve just tested it. It works.

br

Leave a comment