It seems to me that it would be better to encourage use of the `length`
template filter with the `{% if %}` template tag which can provide more
flexibility:
{{{#!django
{# Before: #}
{% if value|length_is:"4" %}...{% endif %}
{{ value|length_is:"4" }} ← This is of dubious use given the restricted
set of possible output values.
{# After: #}
{% if value|length == 4 %}...{% endif %}
{% if value|length == 4 %}True{% else %}False{% endif %} ← Much clearer
but also allows customising the output values.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33864>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/15869 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:1>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:2>
Old description:
> The `length_is` template filter is a vestige from the days of the `{%
> ifequal %}` and `{% ifnotequal %}` days before `{% if %}` arrived with
> support for comparison with operators. Even the example in the
> documentation (see
> [https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#length-is
> here]) is poor: `{{ value|length_is:"4" }}` will only return one of three
> possible values - `True`, `False`, or `""`, the empty string being for
> errors in the provided values.
>
> It seems to me that it would be better to encourage use of the `length`
> template filter with the `{% if %}` template tag which can provide more
> flexibility:
>
> {{{#!django
> {# Before: #}
> {% if value|length_is:"4" %}...{% endif %}
> {{ value|length_is:"4" }} ← This is of dubious use given the restricted
> set of possible output values.
>
> {# After: #}
> {% if value|length == 4 %}...{% endif %}
> {% if value|length == 4 %}True{% else %}False{% endif %} ← Much clearer
> but also allows customising the output values.
> }}}
New description:
The `length_is` template filter is a vestige from the days of the `{%
ifequal %}` and `{% ifnotequal %}` tags before `{% if %}` arrived with
support for comparison with operators. Even the example in the
documentation (see
[https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#length-is
here]) is poor: `{{ value|length_is:"4" }}` will only return one of three
possible values - `True`, `False`, or `""`, the empty string being for
errors in the provided values.
It seems to me that it would be better to encourage use of the `length`
template filter with the `{% if %}` template tag which can provide more
flexibility:
{{{#!django
{# Before: #}
{% if value|length_is:"4" %}...{% endif %}
{{ value|length_is:"4" }} ← This is of dubious use given the restricted
set of possible output values.
{# After: #}
{% if value|length == 4 %}...{% endif %}
{% if value|length == 4 %}True{% else %}False{% endif %} ← Much clearer
but also allows customising the output values.
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"4d4bf55e0ea849476f7e3abfeb018c338f18a9b4" 4d4bf55]:
{{{
#!CommitTicketReference repository=""
revision="4d4bf55e0ea849476f7e3abfeb018c338f18a9b4"
Fixed #33864 -- Deprecated length_is template filter.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"14ef92fa9e87a77cd3642235387e6f683048046b" 14ef92f]:
{{{
#!CommitTicketReference repository=""
revision="14ef92fa9e87a77cd3642235387e6f683048046b"
Refs #33864 -- Removed length_is template filter per deprecation timeline.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33864#comment:6>