@mark_safe decorator and filters & tags

46 views
Skip to first unread message

Torsten Bronger

unread,
May 8, 2018, 4:45:14 PM5/8/18
to django...@googlegroups.com
Hallöchen!

Up to Django 1.11, I had the following pattern frequently in my
code:

@register.filter
@mark_safe
def myfilter(value):
...

Smilarly for tags. This has worked for years, however, with Django
2.0, this leads to the TemplateError saying that "myfilter requires
0 arguments, 1 provided". For tags, it results in an IndexError
because the "params" list when processing the tag is empty.

If I make @mark_safe the outmost (i.e. first) decorator, no
exception occurs – but the output is escaped HTML instead of
passed-through HTML.

The safe and obvious workaround is to use mark_safe() as a function
instead of @mark_safe. Would be a pity, though.

Is this a bug or am I doing something wrong?

Tschö,
Torsten.

--
Torsten Bronger

Tim Graham

unread,
May 12, 2018, 2:40:36 PM5/12/18
to Django users
Reply all
Reply to author
Forward
0 new messages