Michael S
Michael S

Reputation: 189

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?

Upvotes: 6

Views: 5165

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599450

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.

Upvotes: 15

Related Questions