Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display unescaped HTML String in Django Admin change list

I am currently facing a serious problem. I use the standard django admin interface incl. change list to display one of my models. The model has got a field, which includes a link (e.g. in database: http://localhost:8000/data/somefile.pdf'>link).

What I want now is that this string is rendered unescaped and displayed as link. I already tried the following in "change_list_results.html":

{% for result in results %}
<tr id="{{ result.1|adminfilter }}" class="{% cycle 'row1' 'row2' %}">
    {% for item in result %}
        {{ item|safe }}
    {% endfor %}</tr>
{% endfor %}

I used "|safe" on the actual item that is output. Furthermore i tried "{% autoescape off %}". Same result, the String got escaped.

Do you see any other way to get the String displayed unescaped?

like image 303
Michael S Avatar asked Aug 04 '10 11:08

Michael S


1 Answers

You want to set allow_tags=True on your method. It's a bit hidden, but it is described in the documentation - about a screen or so down from where this link takes you.

like image 51
Daniel Roseman Avatar answered Nov 15 '22 07:11

Daniel Roseman