![](/img/trans.png)
[英]How to display a script tag with json content in a code block in html?
[英]How to display html table code in script?
I have a simple html bootstrap which I can display the html blo code returned by a django view.py render function the following code:
<h2 class="mb-4" style="text-align:center"></h2>
{{table|safe}}
它工作得很好。
但是我需要在for循環中打印幾個表,所以我尋找了一個腳本模式。 在這種情況下,它將 html 代碼作為字符串返回。
下面的代碼:
<script>
const tabela = {{table|safe}};
document.write(tabela);
</script>
編輯:我的 views.py 看起來像這樣:
def index(request):
content = {}
content['table'] = resultados_html #resultados_html is a html block code. Currently it's just one table.
return render(request, 'index.html',content)
我不知道您的視圖看起來如何,但您可以在模板中使用for
循環,如下所示:
{% for table in table_list %}
{{table|safe}}
{% endfor %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.