How can i use the django with template tag in external JavaScript file?
I tried to use it like this:
<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>
But it gives error in console Uncaught SyntaxError: Unexpected token with. I think the issue is with is the keyword for JavaScript also, so what is the solution?
If you want your file to contain Django template tags then it must be processed by the Django template engine. Create a new view that sends the proper
Content-typeheader for JavaScript source and then processes and outputs the template that contains JavaScript.