Opened 6 years ago

Closed 6 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@…> 6 years ago.
decode_entities and tests
5821_decode_entities.2.patch (4.1 KB) - added by Samuel Adam <samuel.adam@…> 6 years ago.
decode_entities and test ( fixed regexp )

Download all attachments as: .zip

Change History (4)

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

decode_entities and tests

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

decode_entities and test ( fixed regexp )

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 6 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.