如何在外部JavaScript文件中使用djangowith
模板标记?
我试着这样使用它:
<script>
//some code
//
{% with user|get_song_rating:opts.id as rated %}
{% if rated %}
$off.unbind('click').unbind('mousemove').unbind('mouseenter').unbind('mouseleave');
$off.css('cursor', 'default'); $on.css('cursor', 'default');
$this.attr('title', 'Your rating: ' + rated.points.toFixed(1));
{% endif %}
{% endwith %}
</script>
但它在控制台Uncaught SyntaxError: Unexpected token with
中出错。我认为问题是with
也是JavaScript的关键字,那么解决方案是什么呢?在
如果希望文件包含Django模板标记,则必须由Django模板引擎处理。创建一个新视图,为JavaScript源发送正确的
Content-type
头,然后处理并输出包含JavaScript的模板。在相关问题 更多 >
编程相关推荐