Opened 10 years ago

Closed 9 years ago

#5821 closed (wontfix)

Adds decode_entities to utils.html

Reported by: Samuel Adam <samuel.adam@…> Owned by: nobody
Component: Tools Version: master
Severity: Keywords: html
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


This patch adds html entities decoding function to utils.html


Replaces HTML entities (name, decimal and hexadecimal) with unicode equivalents.

Ampersands, quotes and carets are not replaced by default.


decode_entities can be used to normalize and store user input from a js html editor for example.
If you need to cut a string that could contain HTML entities, you can decode it before the cut without the fear of cutting through an entity.


>>> from django.utils.html import decode_entities
>>> html = u'&lt;D&eacute;j&agrave; &#9001;&gt;'
>>> decode_entities(html)
u'&lt;D\xe9j\xe0 \u2329&gt;'
>>> decode_entities(html, decode_all=True)
u'<D\xe9j\xe0 \u2329>'

Attachments (2)

5821_decode_entities.patch (4.1 KB) - added by Samuel Adam <samuel.adam@…> 10 years ago.
decode_entities and tests
5821_decode_entities.2.patch (4.1 KB) - added by Samuel Adam <samuel.adam@…> 10 years ago.
decode_entities and test ( fixed regexp )

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by Samuel Adam <samuel.adam@…>

Attachment: 5821_decode_entities.patch added

decode_entities and tests

Changed 10 years ago by Samuel Adam <samuel.adam@…>

decode_entities and test ( fixed regexp )

comment:1 Changed 10 years ago by Simon G <dev@…>

Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 9 years ago by Jacob

Resolution: wontfix
Status: newclosed

This is a good candidate for a custom template tag in a third-party app or library, but it's a bit too special case for Django proper.

Note: See TracTickets for help on using tickets.
Back to Top