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?
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?
It would. But use the in
operator instead of the find()
method.
Example:
{% if thestring|contains:"1" %}
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.
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.