第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

嘗試從 JSON 創(chuàng)建 HTML 表時(shí),Jinja2 for 循環(huán)無(wú)法按預(yù)期工作

嘗試從 JSON 創(chuàng)建 HTML 表時(shí),Jinja2 for 循環(huán)無(wú)法按預(yù)期工作

江戶川亂折騰 2023-02-07 15:59:59
我當(dāng)前的代碼返回大量沒(méi)有數(shù)據(jù)的行。不確定我對(duì) jinja2 模板中的 for 循環(huán)做錯(cuò)了什么。我嘗試{{ tables[0][0] }}在 for 循環(huán)內(nèi)使用但收到錯(cuò)誤。jinja2.exceptions.TemplateSyntaxError: 預(yù)期的標(biāo)記 ':',得到 '}'使用 jquery 之類的東西從 JSON 創(chuàng)建 HTML 表會(huì)更好嗎?app.py(縮短代碼)@app.route('/', methods=['GET', 'POST'])def index():    def stockOwnership(ticker):           ...            # prints dataframe to html            table_13D = df_13D.to_json(orient='records')            table_13F = df_13F.to_json(orient='records')              print(table_13D)               #variables holding functions to be passed into tables list    ownership = stockOwnership(stock)        return render_template('index.html', tables=[ownership])索引.html{% extends 'base.html' %}{% block title %} <title>Stock Info</title>{% endblock %}{% block body %}    <h1>Ownership</h1>        <center><h4 class="title-name">13D/G Filings</h4></center>        <table class="table table-striped", id='13D'>            <thead>                 <tr class="bg-info">                     <th>File Date</th>                     <th>Form</th>                     <th>Investors</th>                     <th>Shares</th>                 </tr>             </thead>             <tbody id="mydata">                {%for data in tables[0][0]%}                <tr>                    <td>{{data.File_Date}}</td>                    <td>{{data.Form}}</td>                    <td>{{data.Investors}}</td>                    <td>{{data.Shares}}</td>                </tr>                {%endfor%}            </tbody>        </table> json 通過(guò) {{ 表 [0][0] }}[   {      "File_Date":"2020-04-29",      "Form":"13D\/A",      "Investors":"ARMISTICE CAPITAL, LLC",      "Shares":"407,373"   },   {      "File_Date":"2020-03-23",      "Form":"13G",      "Investors":"INTRACOASTAL CAPITAL, LLC",      "Shares":"3,517,022"   },   {      "File_Date":"2020-03-12",      "Form":"13G",      "Investors":"Sabby Management, LLC",      "Shares":"6,000,000"   },]
查看完整描述

2 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊

不確定這{{ tables[0][0] }}是否是訪問(wèn) of 類型dict的第一個(gè)元素list的有效方法dicts。據(jù)我了解,您目前有一個(gè)listof dicts,因此如果您想將單個(gè)數(shù)據(jù)字典更新為一行,那么您可以使用這樣的語(yǔ)法。


{% for dict_item in parent_list %}

   {% for key, value in dict_item.items() %}

      <h1>Key: {{key}}</h1>

      <h2>Value: {{value}}</h2>

   {% endfor %}

{% endfor %}

因此,您可以使用<td>Value: {{value}}</td>來(lái)呈現(xiàn)<td>一行中的值而不是<td>{{data.File_Date}}</td>. 這應(yīng)該可以有效地解決您的問(wèn)題。


查看完整回答
反對(duì) 回復(fù) 2023-02-07
?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

我認(rèn)為以下行是錯(cuò)誤的
{%for data in tables[0][0]%}

在此上下文中,您從表中獲取數(shù)據(jù),表是包含字典的列表。tables[0] 將為您提供列表中的第一個(gè)字典。現(xiàn)在,當(dāng)您使用語(yǔ)法 tables[0][0] 時(shí),您正在嘗試使用 0(零)作為鍵來(lái)訪問(wèn)字典。如果沒(méi)有密鑰 0(零),您將收到密鑰錯(cuò)誤。


查看完整回答
反對(duì) 回復(fù) 2023-02-07
  • 2 回答
  • 0 關(guān)注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)