Skip to main content

escape

Return the given text with ampersands, quotes and angle brackets encoded for use in HTML.

Always escape input, even if it's already escaped and marked as such.
This may result in double-escaping. If this is a concern, use
conditional_escape() instead.
def escape(
text: Any
) - > SafeString

Return the given text with ampersands, quotes and angle brackets encoded for use in HTML. Always escape input, even if it's already escaped and marked as such. This may result in double-escaping. If this is a concern, use conditional_escape() instead.

Parameters

NameTypeDescription
textAnyThe content to be escaped; it will be converted to a string before processing.

Returns

TypeDescription
SafeStringThe HTML-encoded string, marked as safe for further HTML rendering to prevent double-escaping by template engines.