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

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

商品未顯示在購物車中

商品未顯示在購物車中

素胚勾勒不出你 2021-11-16 16:25:36
所以我試圖在我添加的籃子中顯示該項目,但沒有顯示任何內(nèi)容。@phones.route("/cartt")def shopping_cart():total_price = 0if "cart" not in session:    flash("There is nothing in your cart.")    return render_template("phones/cart.html", display_cart = {}, total = 0)else:    items = [j for i in session["cart"] for j in i]    dict_of_phones = {}    phone_by_id = None    for item in items:        phone = get_phone_by_id(item)        print(phone.id)        total_price += phone.price        dict_of_phones = phone    return render_template('phones/cart.html', display_cart = dict_of_phones, total = total_price)html:   {% for phone in dict_of_phones %}    <tr>        <td>{{phone.model}}</td>        <td>{{phone.year}}</td>        <td>${{ "%.2f" % phone.price}}</td>        <td>${{ "%.2f" % phone.price}}</td></tr>    {% endfor %}
查看完整描述

2 回答

?
白板的微信

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

您在模板中使用了錯誤的變量名稱。它應(yīng)該是 display_cart 而不是 dict_of_phones。見下文:


{% for phone in display_cart %}

    <tr>

        <td>{{phone.model}}</td>

        <td>{{phone.year}}</td>

        <td>${{ "%.2f" % phone.price}}</td>

        <td>${{ "%.2f" % phone.price}}</td>

    </tr>    

{% endfor %}


查看完整回答
反對 回復(fù) 2021-11-16
?
森欄

TA貢獻(xiàn)1810條經(jīng)驗 獲得超5個贊

我會將電話列表傳遞到您的模板中,而不是電話字典。此外,您dict_of_phones就是只設(shè)置到您的手機項目的最后一個值,因為你覆蓋了每一次它的價值dict_of_phones = phone。所以dict_of_phones實際上只是items 中最后一個項目給出的單個電話項目:phone = get_phone_by_id(item)。也許你可以修改你的代碼來創(chuàng)建一個電話列表?然后將此列表傳遞到您的jinja2模板中,大致如下:


@phones.route("/cartt")

def shopping_cart():

total_price = 0

if "cart" not in session:

    flash("There is nothing in your cart.")

    return render_template("phones/cart.html", display_cart = {}, total = 0)

else:

    # Assuming items is correct, looks off

    items = [j for i in session["cart"] for j in i]

    phones = []


    for item in items:

        phone = get_phone_by_id(item)

        print(phone.id)

        # assuming phone has id,model,year, and price attributes

        phones.append[phone]

        # note total_price of your cart not currently being used in your template

        total_price += phone.price

    return render_template('phones/cart.html', display_cart=phones, total = total_price)

然后在您的模板中,您可以執(zhí)行以下操作:


{% for phone in display_cart %}

    <tr>

        <td>{{phone.model}}</td>

        <td>{{phone.year}}</td>

        <td>${{ "%.2f" % phone.price}}</td>

        <td>${{ "%.2f" % phone.price}}</td>

    </tr>    

{% endfor %}

希望這有幫助!


查看完整回答
反對 回復(fù) 2021-11-16
  • 2 回答
  • 0 關(guān)注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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