我在结帐视图上提交表单时遇到问题。 首先,我在主视图上有一个表格,要求输入数量。我将数据发布到结帐视图,以在前端进行摘要。 在我的“结帐”视图中,我还有另一种表单,我在其中询问电子邮件和姓名,当我尝试提交结帐表单时,我遇到了TypeError。
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
这是我的结帐视图
# My view
@login_required(login_url='login')
def checkout(request):
data = request.POST.copy()
region = data.get('region-select')
plateform = data.get('plateform-select')
quantity = data.get('quantity-field')
quantity = int(quantity)
price = quantity * 3.99
context = {
'region':region,
'plateform':plateform,
'quantity':quantity,
'price':price
}
return render(request, 'main/checkout.html', context)
我不明白为什么会这样,因为数据已在我的模板中呈现
<h1 class="title is-5" style="margin-bottom:5px;"> {{price|floatformat:2}} EUR </h1>