Ticket #8966: 8966_with_docs.diff

File 8966_with_docs.diff, 1.3 KB (added by Carl Meyer, 10 years ago)

same patch, with warning note in docs

  • django/template/defaultfilters.py

    476476def length_is(value, arg):
    477477    """Returns a boolean of whether the value's length is the argument."""
    478478    return len(value) == int(arg)
    479 length_is.is_safe = True
    481480def random(value):
    482481    """Returns a random item from the list."""
  • docs/howto/custom-template-tags.txt

    241241       this tricky, but keep an eye out for any problems like that when
    242242       reviewing your code.
     244       Marking a filter ``is_safe`` will coerce the filter's return value to
     245       a string.  If your filter should return a boolean or other non-string
     246       value, marking it ``is_safe`` will probably have unintended
     247       consequences (such as converting a boolean False to the string
     248       'False').
    244250    2. Alternatively, your filter code can manually take care of any necessary
    245251       escaping. This is necessary when you're introducing new HTML markup into
    246252       the result. You want to mark the output as safe from further
Back to Top