1
这是我的模板形式, 我创造与环中两个按钮多种形式投票支持特定项目 ,我认为这是丑陋的,我怎么能避免所有按钮只使用一种形式?如何创建一个表单与环中多个按钮
{% for bill_item in bill_items %}
<form action="{% url 'bills:change_quantity' bill_item.id %}" method="post">
{% csrf_token %}
<button name="up"></button>
<button name="down"></button>
</form>
{% endfor %}
这是我的观点
def change_quantity(request, bill_item_id):
bill_item = BillItem.objects.get(pk=bill_item_id)
if 'up' in request.POST:
bill_item.increase()
elif 'down' in request.POST:
bill_item.decrease()
bill_item.save()
return HttpResponseRedirect('/bills/')