MCPcopy
hub / github.com/django/django / format_html

Function format_html

django/utils/html.py:135–145  ·  view source on GitHub ↗

Similar to str.format, but pass all arguments through conditional_escape(), and call mark_safe() on the result. This function should be used instead of str.format or % interpolation to build up small HTML fragments.

(format_string, *args, **kwargs)

Source from the content-addressed store, hash-verified

133
134
135def format_html(format_string, *args, **kwargs):
136 """
137 Similar to str.format, but pass all arguments through conditional_escape(),
138 and call mark_safe() on the result. This function should be used instead
139 of str.format or % interpolation to build up small HTML fragments.
140 """
141 if not (args or kwargs):
142 raise TypeError("args or kwargs must be provided.")
143 args_safe = map(conditional_escape, args)
144 kwargs_safe = {k: conditional_escape(v) for (k, v) in kwargs.items()}
145 return mark_safe(format_string.format(*args_safe, **kwargs_safe))
146
147
148def format_html_join(sep, format_string, args_generator):

Callers 15

render_password_as_hashFunction · 0.90
action_checkboxMethod · 0.90
response_addMethod · 0.90
response_changeMethod · 0.90
format_callbackFunction · 0.90
display_for_fieldFunction · 0.90
label_tagMethod · 0.90
get_admin_urlMethod · 0.90
paginator_numberFunction · 0.90
result_headersFunction · 0.90
_boolean_iconFunction · 0.90

Calls 4

mark_safeFunction · 0.90
conditional_escapeFunction · 0.85
itemsMethod · 0.45
formatMethod · 0.45

Tested by 2

test_format_htmlMethod · 0.72