mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #29400 -- Fixed crash in custom template filters that use decorated functions.
Regression in 620e9dd31a
.
This commit is contained in:
parent
96ea4f875b
commit
a8d12bc280
5 changed files with 18 additions and 3 deletions
|
@ -3,6 +3,7 @@ import operator
|
|||
from django import template
|
||||
from django.template.defaultfilters import stringfilter
|
||||
from django.utils.html import escape, format_html
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
@ -13,6 +14,13 @@ def trim(value, num):
|
|||
return value[:num]
|
||||
|
||||
|
||||
@register.filter
|
||||
@mark_safe
|
||||
def make_data_div(value):
|
||||
"""A filter that uses a decorator (@mark_safe)."""
|
||||
return '<div data-name="%s"></div>' % value
|
||||
|
||||
|
||||
@register.filter
|
||||
def noop(value, param=None):
|
||||
"""A noop filter that always return its first argument and does nothing with
|
||||
|
|
|
@ -25,6 +25,11 @@ class CustomFilterTests(SimpleTestCase):
|
|||
"abcde"
|
||||
)
|
||||
|
||||
def test_decorated_filter(self):
|
||||
engine = Engine(libraries=LIBRARIES)
|
||||
t = engine.from_string('{% load custom %}{{ name|make_data_div }}')
|
||||
self.assertEqual(t.render(Context({'name': 'foo'})), '<div data-name="foo"></div>')
|
||||
|
||||
|
||||
class TagTestCase(SimpleTestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue