other than encapsulating the variable in a string, an alternate is jquery for profit:
its generally a bad idea to mix template language with javascript. An alternative would be to use html as a proxy - store the name in an element like so
<meta id="my-data" data-name="{{name}}" data-other="{{other}}">
then in the javascript do
var djangoData = $('#my-data').data();
this has advantage in:
- javascript no longer tied to the .html page
- jquery coerces data implicitly
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…