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

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

Python / SQL 不顯示連接的數(shù)據(jù)庫到表

Python / SQL 不顯示連接的數(shù)據(jù)庫到表

泛舟湖上清波郎朗 2021-09-14 21:36:17
我有一個(gè)連接的 SQL 花卉數(shù)據(jù)庫(屬、種、名稱),其中填充了一個(gè)只顯示該信息的表。我只能讓屬列正確填充,但不能正確填充物種/名稱列。工作代碼 - 正確顯示一列:更新.html<!--this is for the table -->   <div class="container">       <div class="row">           <div class="col">               <table id="table" border="1">                   <tr>                       <th class="cell">Genus</th>                       <th class="cell">Species</th>                       <th class="cell">Comname</th>                   </tr>                   <!--the next line with the python code works as long as you only want the genus information-->                   {% for g in genus_update %}                   <tr>                       <td class="cell">{{g}}</td>                       <!--<td class="cell">{{g}}</td>-->                       <!--<td class="cell">{{c}}</td>-->                   </tr>                   {% endfor %}               </table>           </div>           <div class="col">               <!--the right column so that everything is lined up on the left side-->           </div>       </div>   </div>嘗試為其他人使用 for 循環(huán)會破壞頁面(不確定為什么):{% for s in species_update %}  <tr>    <td class="cell">{{s}}</td>  </tr>{% endfor %}{% for c in comname_update %}  <tr>    <td class="cell">{{c}}</td>  </tr>{% endfor %}蟒蛇.py:from flask import Flask, render_template, request, gimport sqlite3app = Flask (__name__)# conn = sqlite3.connect('flowers.db')# c = conn.cursor()DATABASE = 'flowers.db'def get_db():   db = getattr(g, '_database', None)   if db is None:       db = g._database = sqlite3.connect(DATABASE)   return db@app.teardown_appcontextdef close_connection(exception):   db = getattr(g, '_database', None)   if db is not None:       db.close()@app.route('/')def index():   c = get_db().cursor()   c.execute('SELECT COMNAME FROM FLOWERS')   all_flowers = c.fetchall()   return render_template("index.html", all_flowers=all_flowers)
查看完整描述

3 回答

?
慕哥9229398

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

解決了

解決方案


html代碼:


{% for g, s, c in genus_flowers%}

                   <tr>

                       <td class="cell">{{g}}</td>

                       <td class="cell">{{s}}</td>

                       <td class="cell">{{c}}</td>


                   </tr>

{% endfor %}

蟒蛇代碼:


@app.route('/update')

def update():

   c = get_db().cursor()

   # this just gets the data from the db


   c = get_db().cursor()

   c.execute('SELECT GENUS, SPECIES, COMNAME FROM FLOWERS')

   genus_flowers = c.fetchall()

   return render_template("update.html", genus_flowers=genus_flowers)


查看完整回答
反對 回復(fù) 2021-09-14
?
狐的傳說

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

我知道在 Django 中,python 的另一個(gè) web 框架,你必須引用對象中的字段,而不僅僅是對象本身。因此,如果您執(zhí)行 Select *,而不是 Select 'field':


@app.route('/update')

def update():

   c = get_db().cursor()

   # this just gets the data from the db

   c.execute('SELECT * FROM FLOWERS')

   flowers = c.fetchall()

   zipped = zip(genus_update, species_update)

   return render_template("update.html", flowers=flowers, zipped=zipped)

然后,您可以執(zhí)行以下操作:


<!--this is for the table -->

   <div class="container">

       <div class="row">

           <div class="col">

               <table id="table" border="1">

                   <tr>

                       <th class="cell">Genus</th>

                       <th class="cell">Species</th>

                       <th class="cell">Comname</th>

                   </tr>

                   <!--the next line with the python code works as long as you only want the genus information-->

                   {% for f in flowers %}

                   <tr>

                       <td class="cell">{{ f.genus }}</td>

                       <td class="cell">{{ f.species }}</td>

                       <td class="cell">{{ f.comname }}</td>

                   </tr>

                   {% endfor %}

               </table>

           </div>

           <div class="col">

           </div>

       </div>

   </div>



查看完整回答
反對 回復(fù) 2021-09-14
?
拉丁的傳說

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

我不確定這里究竟會發(fā)生什么,但由于我處于這種情況之前,我建議您先測試是否從數(shù)據(jù)庫中獲取數(shù)據(jù),而不是直接檢查 Flask 呈現(xiàn)它的部分。確保傳遞的查詢的數(shù)據(jù)也存在。

希望這將有助于進(jìn)展。


查看完整回答
反對 回復(fù) 2021-09-14
  • 3 回答
  • 0 關(guān)注
  • 421 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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