Reputation: 259
while writing an application in django, I've encountered a problem. I want to make page-number links, with current page not being a link. So in template I do this:
{% for i in pages %}
{% if i == curr_page %} {{ i }}
{% else %} <a href="...">{{ i }}</a>
{% endif %}
Only problem? Jinja doesn't seem to notice two numbers being equal. I've changed the 2nd line to {% if i != curr_page %} {{i}}!={{curr_page}}
and got "... 5!=6 6!=6 7!=6 ...".
What should I do?
Upvotes: 1
Views: 1898
Reputation: 5110
Because they are not of same data type. In your view, cast them to int
before passing to context dict
.
pages = list(map(int, pages))
curr_page = int(curr_page)
Upvotes: 3