mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #17419 -- Added json_tag template filter.
This commit is contained in:
@@ -12,8 +12,8 @@ from django.utils import formats
|
||||
from django.utils.dateformat import format, time_format
|
||||
from django.utils.encoding import iri_to_uri
|
||||
from django.utils.html import (
|
||||
avoid_wrapping, conditional_escape, escape, escapejs, linebreaks,
|
||||
strip_tags, urlize as _urlize,
|
||||
avoid_wrapping, conditional_escape, escape, escapejs,
|
||||
json_script as _json_script, linebreaks, strip_tags, urlize as _urlize,
|
||||
)
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
from django.utils.text import (
|
||||
@@ -82,6 +82,15 @@ def escapejs_filter(value):
|
||||
return escapejs(value)
|
||||
|
||||
|
||||
@register.filter(is_safe=True)
|
||||
def json_script(value, element_id):
|
||||
"""
|
||||
Output value JSON-encoded, wrapped in a <script type="application/json">
|
||||
tag.
|
||||
"""
|
||||
return _json_script(value, element_id)
|
||||
|
||||
|
||||
@register.filter(is_safe=True)
|
||||
def floatformat(text, arg=-1):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user