簡體   English   中英

如何在腳本中顯示 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM