On this page
html.escape
Up: html | Next: html.unescape
Rel: html.unescape
Ref: docs.python.org — html.escape
Tags: #public #python3 #stdlib #html
Import
import html
from html import escape
Signature & Overview
html.escape(s, quote=True)
Replace special characters "&", "<" and ">" to HTML-safe sequences.
Usage
import html
assert html.escape('<a href="x">A & B</a>') == '<a href="x">A & B</a>'
Gotchas
- Context matters:
html.escape()protects HTML text and quoted attributes, not unquoted attributes,<script>, orhref="javascript:..."URLs.
REPL Inspect
from html import escape
help(escape)
Linked from
Related notes
- tuts/python3/stdlib_module/html/unescape Linked here; links to this page; shared tags: #html, #stdlib
- tuts/python3/stdlib_module/html Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib
- tuts/c/stdlib/ctype/isspace shared tags: #stdlib