Skip to main content

conditional_escape

Similar to escape(), except that it doesn't operate on pre-escaped strings.

This function relies on the html convention used both by Django's SafeData class and by third-party libraries like markupsafe.

def conditional_escape(
text: Any
) - > string

Similar to escape(), except that it doesn't operate on pre-escaped strings. This function relies on the html convention used both by Django's SafeData class and by third-party libraries like markupsafe.

Parameters

NameTypeDescription
textAnyThe input to be escaped, which may be a string, a lazy translation promise, or an object implementing the html protocol.

Returns

TypeDescription
stringThe HTML-escaped string, or the original string if it is already marked as safe via the html method.