Jinja2

From PedrosBrainDump
Revision as of 03:29, 10 November 2024 by 413vhcu1lq0463ob (talk | contribs) (→‎Check by a pattern on the end of a string)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Check a pattern on a string

Check by a pattern on the beginning of a string

{% if my_string.startswith('pattern') %}{% endif %}
{% if my_string[:len('pattern')] == 'pattern' %}{% endif %}

Check by a pattern on the end of a string

{% if my_string.endswith('pattern') %}{% endif %}
{% if my_string[-len('pattern'):] == 'pattern' %}{% endif %}

Check by a pattern into a string

{% if 'pattern' in my_string %}{% endif %}