![](/img/trans.png)
[英]How to send an email using a html template that contains javascript django?
[英]How to send the html string to django template javascript?
這是我從django視圖發送到django模板的html字符串的內容,
def myview(request):
return render(request, 'mypage.html',{'html': """" <p>sdgsajdgjs</p>
<pre><code>fafkjhfd
</code></pre> """})
的mypage.html:
<script>
var html = "{{ html }}"
</script>
但是我Uncaught SyntaxError: Unexpected token ILLEGAL
這個錯誤: Uncaught SyntaxError: Unexpected token ILLEGAL
。 我知道此錯誤,因為所有HTML代碼均未視為字符串。 請給我答復如何解決此錯誤。
使用escapejs過濾器。 嘗試這個,
<script>
{% autoescape off %}
var html = "{{ html|escapejs }}"
{% endautoescape %}
</script>
更新:
{% autoescape off %}
{% filter escapejs %}
{% include "....html" with x=y %}
{% endfilter %}
{% endautoescape %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.