Opened 7 years ago

Closed 7 years ago

#17239 closed Cleanup/optimization (fixed)

mark_safe(media) in django admin Opzioni

Reported by: Riccardo Di Virgilio Owned by: Piotr Banaszkiewicz
Component: contrib.admin Version: master
Severity: Normal Keywords: mark_safe media
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


a minor bug in django admin.

in django.contrib.admin.options mark_safe is called to render media.
in add_view and change_view we can find mark_safe(media)

in changelist_view media is injected as an object (without mark_safe)
i propose to pass the media object to the template (without
mark_safe), because i use a template tag that adds media.

so i check in the context if there is 'media' key, and then merge my
own list of javascript and css with the existing django media.

but i cannot do this if the media object is rendered before it is
passed to the context processor.

Attachments (1)

remove_unnecessary_mark_safe_17239.diff (1012 bytes) - added by Piotr Banaszkiewicz 7 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization


  • changelist_view passes an instance of forms.Media in the context, and admin/change_list.html renders separately {{ media.css }} and {{ media.js }};
  • add_view and change_view passes a string, rendered as a side effect of calling mark_safe, and admin/change_form.html renders directly {{ media }}.

It could be worth to resolve this inconsistency, which appeared at r10077 and doesn't seem justified.

comment:2 Changed 7 years ago by Piotr Banaszkiewicz

Owner: changed from nobody to Piotr Banaszkiewicz

Changed 7 years ago by Piotr Banaszkiewicz

comment:3 Changed 7 years ago by Piotr Banaszkiewicz

Has patch: set

The change is harmless, as django.forms.widgets.Media is being "marked_safe" upon rendering in template.

comment:4 Changed 7 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:5 Changed 7 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [17475]:

(The changeset message doesn't reference this ticket)

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