django模板标记的未终止字符串文字错误 [英] unterminated string literal error for a django template tag
问题描述
我有以下代码片段,它给了我未终止的字符串文字错误
I have the following snippet of code which gives me unterminated string literal error
$(function() {
$('#addDropdown').click(function() {
var $d = $('{{ form |bootstrap }}').fadeIn().delay(1000);
$('#dropdownContainer').append($d);
});
});
我看过未终止的字符串文字问题
,发现这是因为多行问题。我{{form | bootstrap}}有多行代码,如问题所述。所以我该怎么办处理问题
I have looked unterminated string literal question and found that it is because multiline problem.My {{ form |bootstrap }} has multiple lines of code as mentioned in the question.So how do I handle the problem
推荐答案
一般情况下,要使用JavaScript,你应该使用 | escapejs
过滤器:
In general, to use with JavaScript, you should use |escapejs
filter:
var $ d = $('{{value | escapejs}}');
但是,作为最佳实践,您最好将 {{form | bootstrap}}
放入HTML,并使用JavaScript来淡入:
However, as a matter of best practice you'd better put {{ form|bootstrap }}
in HTML, and use JavaScript just to fade in:
<div id="djangoForm" style="display:none">{{ form|bootstrap }}</div>
<script>
$('#addDropdown').click(function() {
$('#dropdownContainer').append($('#djangoForm'));
}
</script>
这篇关于django模板标记的未终止字符串文字错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!