我通过Django管理面板输入了一个包含嵌入式<a>
的responsibility.description
。在模板中显示时,我希望<a>
作为链接出现,而不是被转义为<a&rt;
。
我找到了这个建议(如何在Django feeds中禁用自动转义?),但似乎对我没有用。
我尝试将其标记为safe
:
{% for responsibility in software.responsibilities.all %}
<li>{{ responsibility.description|safe }}</li>
{% endfor %}
同时也要关闭autoescape
:
{% for responsibility in software.responsibilities.all %}
{% autoescape off %}
<li>{{ responsibility.description }}</li>
{% endautoescape %}
{% endfor %}
我是否遗漏了什么或者还有其他方法可以尝试?
以下是存储在数据库中的数据:
>>> Responsibility.objects.filter(id=38)
<QuerySet [<Responsibility: Created and ran test suites using a proprietary testing framework for “Stubbs the Zombie” (<a target="_blank" href="http://www.imdb.com/title/tt0498128/fullcredits?ref_=tt_cl_sm#cast">credited</a>), a game for Windows, Mac, and X-Box written in C/C++ utilizing the Halo game engine.>]>
以下是它在html中的显示方式:
<li>Created and ran test suites using a proprietary testing framework for "Stubbs the Zombie" (<a target="_blank" href="http://www.imdb.com/title/tt0498128/fullcredits?ref_=tt_cl_sm#cast">credited</a>), a game for Windows, Mac, and X-Box written in C/C++ utilizing the Halo game engine.</li>