亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

無法渲染特定項目,flask/sqlalchemy

無法渲染特定項目,flask/sqlalchemy

蕪湖不蕪 2023-08-03 16:26:30
嘿,我正在嘗試編寫一個銷售門票的平臺,因此當我作為用戶單擊該活動時,我將被重定向到一個頁面,其中將顯示活動信息,包括價格和內容。就此而言,我試圖打印該特定活動的門票給定價格,但沒有成功,我嘗試了很多方法,但這些是我編碼的最終行。我非常了解如何在 python 中操作列表,但由于這是flask/sqalchemy,我有點困惑,因為門票必須是活動組織者將要設置的門票。帖子.html<div class="table-tickets col-lg-4 col-md-4 col-sm-12 col-xs-12 margin-top-20-xs margin-top-0-md">    <form method="POST" action="">      <table>        <tbody>           <tr class="title">              <th class="tg-031e" colspan="2">                 <div class="row">                   <div class="col-md-6 col-sm-6 col-xs-6 col lg-6">                      <h4 class="kill-top-margin kill-bottom-margin"> Tickets</h4>                  </div>                   <div class="col-md-6 col-sm-6 col-xs-6 col lg-6">                      {% for info in post.ticket %}                    <h4 class="kill-top-margin kill-bottom-margin"> ${{ info }} </h4>                    {% endfor %}                    <h4 class="kill-top-margin kill-bottom-margin"> ${{ #priceoftheticket }} </h4>                 </div>                 </div>              </th>            </tr>        </tbody>      </table>    </form></div>楷模class Post(db.Model):    #unique id for the user    id= db.Column(db.Integer, primary_key=True)    #name of the event    title= db.Column(db.String(100), nullable=False)    #when the event was posted     date_posted= db.Column(db.DateTime, nullable=False, default=datetime.now())    #description of the event    content= db.Column(db.Text, nullable=False)    #start date and hour of the event     start_dh= db.Column(db.String(10), nullable=False, default=datetime.now())    #finish date and hour of the event     finish_dh= db.Column(db.String(10), nullable=False, default=datetime.now())
查看完整描述

1 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

我相信您有兩種選擇:

  1. 只需訪問該屬性:

             {% for info in post.ticket %}
             <h4 class="kill-top-margin kill-bottom-margin"> ${{ info }} </h4>
             <h4 class="kill-top-margin kill-bottom-margin"> ${{ info.price_ticket }} </h4>
             {% endfor %}
  2. 或者,根據它當前的渲染方式并假設它是您需要顯示的唯一位置,您可以在類中ticket重新實現:__repr__Tickets

    def __repr__(self): 
        return "%s" % (self.price_ticket)

    但這可能會對整個應用程序產生影響,我不會推薦它。


查看完整回答
反對 回復 2023-08-03
  • 1 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號