django - Is there a way to check the data type of a context variable in Jinja2? -
django - Is there a way to check the data type of a context variable in Jinja2? -
i trying check type of context variable on jinja2 template, on django app. trying check if variable result
of type <searchresult: myapp.b (pk=u'1')>
or <searchresult: myapp.a (pk=u'1')>
.
here's code trying implement.
context = 'results':form.search()}
x.html
{% result in results %} <!-- if result searchobject of b --> {% ifequal result 'searchresult: myapp.b' %} <div class="container"> <div class="list-group"> <a href="/b/{{ result.pk }}" class="list-group-item"> <h4 class="list-group-item-heading">{{ result.title }}</h4> <h6 class="list-group-item-heading">created on: {{ result.createdon }} </h6> </a> </div> </div> {% endifequal %}
{{result}} prints <searchresult: myapp.b (pk=u'1')>
. so, 2 types myapp.a , myapp.b, want apply 2 separate pieces of code. thanks!
simply utilize {% ifequal result.model_name 'a'%}
django jinja2
Comments
Post a Comment