问题
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