Skip to main content

format_html

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.

def format_html(
format_string: string,
*args: any,
**kwargs: any
) - > SafeString

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.

Parameters

NameTypeDescription
format_stringstringThe template string containing format placeholders to be populated.
*argsanyVariable positional arguments to be escaped and inserted into the format string.
**kwargsanyVariable keyword arguments to be escaped and inserted into the format string.

Returns

TypeDescription
SafeStringThe formatted HTML string with all arguments safely escaped and the final result marked as safe for rendering.