Django and Chartjs template conflict

六眼飞鱼酱① 提交于 2019-12-11 10:04:51

问题


I'm trying to set the tooltipTemplate property of a line chart to <%if (label){%><%=label%>: <%}%><%= value %>, but I'm using Django on the backend. So, if I try to use the literal value of tooltipTemplate, Django will interpret the {% and %} as part of its template language. How can I avoid this?

tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>"


回答1:


You can use the verbatim tag.

{% verbatim %}
    tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>"
{% endverbatim %}

There is also a templatetag tag which you can use to output special template tag characters, but that would be quite verbose.

tooltipTemplate: "<%if (label){% templatetag openblock %}><%=label%>: <%{% templatetag closeblock %}><%= value %>"


来源:https://stackoverflow.com/questions/32523909/django-and-chartjs-template-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!