HTML页面有2个按钮来处理付款,我需要给url传递2个参数,原因是什么?下面是我试过的方法,但是没有用。谁能帮帮我...?
<a href="{% url 'process-payment' order.id button.id %}" id = "CashOnDelivery" class="btn btn-warning"> Cash on Delivery</a>
<a href="{% url 'process-payment' order.id button.id %}" id = "Card" class="btn btn-warning">Pay through Card</a>
views.py
def process_payment(request, order_id, button_id):
if id == CashOnDelivery
# directly take order
return redirect (reverse('update-records', kwargs={'order_id': order_id}))
else
# process the card payment then update transaction
return redirect (reverse('update-records', kwargs={'order_id': order_id}))
urls.py
urlpatterns=[
path('payment/<order_id>/<button_id>',views.process_payment, name='process-payment'),
]
这是因为你的变量没有定义。
<a href="{% url 'process-payment' order.id 'CashOnDelivery' %}" id = "CashOnDelivery" class="btn btn-warning"> Cash on Delivery</a>
.
<a href="{% url 'process-payment' order.id 'Card' %}" id = "Card" class="btn btn-warning">Pay through Card</a>
.
另外,你似乎没有检查正确的ID。
def process_payment(request, order_id, button_id):
if button_id == CashOnDelivery
# directly take order
return redirect (reverse('update-records', kwargs={'order_id': order_id}))
else
# process the card payment then update transaction
return redirect (reverse('update-records', kwargs={'order_id': order_id}))```