簡體   English   中英

Django:在模板渲染中包含另存為字符串的html

[英]Django: include html saved as string in template rendering

我在views.py函數中構建了一個HTML表,並且希望將其包含在渲染時已經具有的模板中。 我看到已創建div ,但未創建HTML表。 問題是什么?

這是views.py的行:

render(request, 'aztracker/import_data.html', {'my_html':html_data})其中html_data就像

"<table><tr><th>column1</th></tr><tr><td>data1</td></tr> ....</table>"

我的import_data.html有此部分:

    <div class="bootstrap-iso">
        <div class="tbl_container_numbers">
            {{ my_html }}
        </div>
    </div>

這是渲染后的sanme div:

    <div class="bootstrap-iso">
        <div class="tbl_container_numbers">

        </div>
    </div>

我發現了問題。 要呈現存儲為字符串的html代碼,我們應該使用內置的autoescape標簽:

    <div class="bootstrap-iso>
        <div class="tbl_container_numbers">
            {% autoescape off %}
                {{ my_html }}
            {% endautoescape %}
        </div>
    </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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