嘿,我正在嘗試編寫一個銷售門票的平臺,因此當我作為用戶單擊該活動時,我將被重定向到一個頁面,其中將顯示活動信息,包括價格和內容。就此而言,我試圖打印該特定活動的門票給定價格,但沒有成功,我嘗試了很多方法,但這些是我編碼的最終行。我非常了解如何在 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個贊
我相信您有兩種選擇:
只需訪問該屬性:
{% 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 %}
或者,根據它當前的渲染方式并假設它是您需要顯示的唯一位置,您可以在類中
ticket
重新實現:__repr__
Tickets
def __repr__(self): return "%s" % (self.price_ticket)
但這可能會對整個應用程序產生影響,我不會推薦它。
添加回答
舉報
0/150
提交
取消