Reputation: 272014
How do I do this:
{% if thestring %}
{% if thestring.find("1") >= 0 %}
{% endif %}
{% endif %}
I am assuming I need to build a template filter? Will that work?
Upvotes: 0
Views: 2137
Reputation: 882023
You don't need to build a custom filter, though one would work -- the alternative of coding
{% if thestring %}
{% if "1" in thestring %}
{% endif %}
{% endif %}
would also go just fine.
Upvotes: 3
Reputation: 32080
I believe you'll find that the Django template system isn't designed to have complex logic in it. This type of processing should happen in your view, then be passed to the template.
Upvotes: 1
Reputation: 798884
It would. But use the in
operator instead of the find()
method.
Example:
{% if thestring|contains:"1" %}
Upvotes: 3