我正在制作计费系统,因为可以从数据库中获取商品的数量及其价格,这些商品可以在index.html模板中查看,在 index.html 文件中,我可以输入字段中,我以单位输入项目数,如何在视图中发送项目数。
index.html
<form method='POST' action="{% url 'bill:total_amount' %}" name= 'myform'>
{% csrf_token %}
<table>
<tr>
<th>Items-Name</th> 
<th><center>Quantity</center></th> 
<th><center>Price[Per_units]</center></th>
</tr>
{% for p in products %}
<tr>
<td>{{ p.product_name }}</td> 
<td><input type="number" min="0" name="quantity" value="0"></td> 
<td><center>{{ p.product_price }}</center></td>
</tr>
{% endfor %}
</table>
<button type="submit" class="btn btn-default">Submit</button>
</form>
views.py
def total_amount(request):
#how to fetch all the values here from form
quantity = request.POST.get('quantity')
#arithmetic operation to be done
return render(request, "bills/bills.html", {})