Как создать простую корзину покупок в Flask, в которую можно добавить несколько товаров, а затем показать все на странице корзины? Как создать простую корзину покупок во Flask, в которую можно добавить несколько товаров, а затем отобразить все на странице корзины?
@app.route('/checkout', methods=['POST'])
def checkout():
user_id = session.get('user_id')
cart = session.get('cart', [])
order_type = request.form['order_type']
conn = get_db()
c = conn.cursor()
for item in cart:
c.execute('''
INSERT INTO orders (user_id, product_id, quantity, order_type, status)
VALUES (?, ?, ?, ?, ?)
''', (user_id, item['id'], item['quantity'], order_type, "Pending"))
conn.commit()
conn.close()
session.pop('cart', None)
return redirect('/orders')