Triste, pero no hay tal funcionalidad en la etiqueta 'if' de django. Hay un rumors that smarter if tag will be added in 1.2., al menos está en la lista High priority
.
Alternativamente, puede utilizar "smart_if" tag from djangosnippets.com
O usted puede añadir su propio filtro (igual como filtro length_is) - pero es sólo añadir más código inútil :(
from django import template
register = template.Library()
def length_gt(value, arg):
"""Returns a boolean of whether the value is greater than an argument."""
try:
return len(value) > int(arg)
except (ValueError, TypeError):
return ''
length_gt.is_safe = False
register.filter(length_gt)
Para más información consultar django docs
Una cosa curiosa: en 1.6 si utiliza espacios como 'myarr | length', django lo imprimirá, pero si intentas comparar, obtienes un error. Para comparar, tuve que eliminar los espacios. – aldux