我想说:转到additemtocart/1
<a href="{{url_for('additemtocart/1')}}">add to cart</a>
但我得到的只是一条错误信息:
werkzeug.routing.BuildError:
无法为终结点“additemtocart/1
”生成url。你是说“额外的艺术”吗
python代码:
carts = []
def addtocart(item):
carts.append({'name': checkusername(), 'items': item})
print(carts)
@app.route('/additemtocart/<id>')
def additemtocart(id):
if checklogin() == True:
try:
title = db.get_select_product(int(id))[5]
addtocart(title)
print(title + ' has been added to your shopping cart')
return redirect(url_for('cart'))
except:
return 'item does not exist'
else:
return redirect(url_for('login'))```
改变
<a href="{{url_for('additemtocart/1')}}">add to cart</a>
至
<a href="{{url_for('additemtocart', ID=1)}}">add to cart</a>
这样,您就可以通过函数/端点传递变量/非静态组件
相关问题 更多 >
编程相关推荐