烧瓶会议清单不起作用

时间:2016-10-21 16:33:02

标签: python flask

我在烧瓶会话中更新列表时遇到问题。

我已经阅读了文档(http://flask.pocoo.org/docs/0.11/api/#sessions)和一些像How to change values in Flask session dictionary using forms?这样的答案,我在追加后使用了session.modified = True,但仍然获得了ReferenceError: weakly-referenced object no longer exists

这是我的代码:

@s_cart.route("/cart")
def shopping_cart():
    if "cart" not in session:
        print("There is nothing in your cart.")
        return render_template("cart.html", lista={}, total=0)
    else:
        items = session["cart"]
        cosas = {}
        print(items)
        total_price = 0
        for item in items:
            cassette = aux_methods.get_cassette(item)
            total_price += cassette.price
            if cassette.id in cosas:
                cosas[cassette.id]["qty"] += 1
            else:
                cosas[cassette.id] = {"qty": 1, "name": cassette.title, "price": cassette.price}

    return render_template("cart.html", lista=cosas, total=total_price)


@s_cart.route("/add_to_cart/<_id>")
def add_to_cart(_id):
    if "cart" not in session:
        session["cart"] = []

    session["cart"].append(_id)
    session.modified = True

    return redirect("/cart")

我无法找到错误。有什么想法吗?

0 个答案:

没有答案