django 给前端传递HTML内容

django从view向template传递HTML字符串的时候,django默认不渲染此HTML,原因是为了防止这段字符串里面有恶意攻击的代码。

如果需要渲染这段字符串,需要在view里这样写:

from django.utils.safestring import mark_safe


pageHtml = mark_safe("<a href='{%url equip:listEquipmentCategory 1 %}'>首页</a>")
ret = {"equit_cate_list":list,"count":count,"ecform":ecform,"page":page,"pageHtml":pageHtml}
return render(request, "list_equip_category.html",ret)

posted @ 2017-08-26 21:55  童小哥总是不开心。  阅读(1774)  评论(0编辑  收藏  举报