Replace make_safe(media) with media in ModelAdmin context dictionary
Currently, the media object is converted to safe string in both add_view
and change_view
methods when added to the context dictionary
while in changelist_view
is not (the correct approach).
Converting media to string means you cannot split css from js in
templates. What I'd like to do is
<head>
...
{% for css in media.render_css %}
{{ css|safe }}{% endfor %}
</head>
<body>
...
{% for js in media.render_js %}
{{ js|safe }}{% endfor %}
</body>
A two lines modification.
Component: |
django.contrib.admin → Forms
|
Patch needs improvement: |
set
|
Triage Stage: |
Unreviewed → Accepted
|
Owner: |
changed from nobody to lsbardel
|
Status: |
new → assigned
|
Needs tests: |
set
|
Patch needs improvement: |
unset
|
Owner: |
changed from lsbardel to Sergey Kolosov
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Valid point (and fix), but you shouldn't need to do the |safe yourself. Django is generating the HTML; it should be considered safe. The contents of render_css and render_js should be marked safe internally ready for rendering.