/shop/process_payment/ 处的 FieldError 无法将关键字 'id' 解析为字段。选项包括:地址、金额、电子邮件、items_json、姓名、order_id、phone
FieldError at /shop/process_payment/ Cannot resolve keyword 'id' into field. Choices are: address, amount, email, items_json, name, order_id, phone
我正在使用 Django 2.1.5 和 Python 3.5
我想将 paypal 支付网关集成添加到我的项目中,但我
遇到这个问题无法将关键字 'id' 解析为字段。选择
是:地址,金额等
def 结帐(请求):
if request.method == "POST":
items_json = request.POST.get('itemsjson', '')
name = request.POST.get('name', '')
amount = request.POST.get('amount', '')
email = request.POST.get('email', '')
address = request.POST.get('address1', '') + " " + request.POST.get('address2', '')
city = request.POST.get('city', '')
state = request.POST.get('state', '')
zip_code = request.POST.get('zip_code', '')
phone = request.POST.get('phone', '')
order = Orders(items_json=items_json, name=name, amount=amount, email=email, address=address, city=city, state=state, zip_code=zip_code, phone=phone)
order.save()
update = OrderUpdate(order_id=order.order_id, update_desc="The order has been placed")
update.save()
thank = True
id = order.order_id
return redirect('process_payment')
return render(request, 'shop/checkout.html', locals())
def process_payment(请求):
order_id = request.session.get('order.order_id')
order = get_object_or_404(Orders, id=order_id)
host = request.get_host()
paypal_dict = {
'business': settings.PAYPAL_RECEIVER_EMAIL,
'amount': str(amount),
'item_name': name,
'invoice': str(order.order_id),
'currency_code': 'USD',
"notify_url": request.build_absolute_uri(reverse('paypal-ipn')),
"return": request.build_absolute_uri(reverse('payment_done')),
"cancel_return": request.build_absolute_uri(reverse('payment_cancelled')),
}
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form}
return render(request, "shop/process_payment.html", context)
我的models.py文件
class 订单(models.Model):
order_id = models.AutoField(primary_key=True)
items_json = models.CharField(max_length=5000)
amount = models.IntegerField(default=0)
name = models.CharField(max_length=90)
email = models.CharField(max_length=120)
address = models.CharField(max_length=120)
city = models.CharField(max_length=120)
state = models.CharField(max_length=120)
zip_code = models.CharField(max_length=120)
phone = models.CharField(max_length=120)
class 订单更新(models.Model):
update_id = models.AutoField(primary_key=True)
order_id = models.IntegerField(default="")
update_desc = models.CharField(max_length=5000)
timestamp = models.DateField(auto_now_add=True)
如果您的订单模型的主键字段不是 id
,请使用 pk
:
order = get_object_or_404(Orders, pk=order_id)
我正在使用 Django 2.1.5 和 Python 3.5
我想将 paypal 支付网关集成添加到我的项目中,但我 遇到这个问题无法将关键字 'id' 解析为字段。选择 是:地址,金额等
def 结帐(请求):
if request.method == "POST": items_json = request.POST.get('itemsjson', '') name = request.POST.get('name', '') amount = request.POST.get('amount', '') email = request.POST.get('email', '') address = request.POST.get('address1', '') + " " + request.POST.get('address2', '') city = request.POST.get('city', '') state = request.POST.get('state', '') zip_code = request.POST.get('zip_code', '') phone = request.POST.get('phone', '') order = Orders(items_json=items_json, name=name, amount=amount, email=email, address=address, city=city, state=state, zip_code=zip_code, phone=phone) order.save() update = OrderUpdate(order_id=order.order_id, update_desc="The order has been placed") update.save() thank = True id = order.order_id return redirect('process_payment') return render(request, 'shop/checkout.html', locals())
def process_payment(请求):
order_id = request.session.get('order.order_id')
order = get_object_or_404(Orders, id=order_id)
host = request.get_host()
paypal_dict = {
'business': settings.PAYPAL_RECEIVER_EMAIL,
'amount': str(amount),
'item_name': name,
'invoice': str(order.order_id),
'currency_code': 'USD',
"notify_url": request.build_absolute_uri(reverse('paypal-ipn')),
"return": request.build_absolute_uri(reverse('payment_done')),
"cancel_return": request.build_absolute_uri(reverse('payment_cancelled')),
}
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form}
return render(request, "shop/process_payment.html", context)
我的models.py文件
class 订单(models.Model):
order_id = models.AutoField(primary_key=True)
items_json = models.CharField(max_length=5000)
amount = models.IntegerField(default=0)
name = models.CharField(max_length=90)
email = models.CharField(max_length=120)
address = models.CharField(max_length=120)
city = models.CharField(max_length=120)
state = models.CharField(max_length=120)
zip_code = models.CharField(max_length=120)
phone = models.CharField(max_length=120)
class 订单更新(models.Model):
update_id = models.AutoField(primary_key=True)
order_id = models.IntegerField(default="")
update_desc = models.CharField(max_length=5000)
timestamp = models.DateField(auto_now_add=True)
如果您的订单模型的主键字段不是 id
,请使用 pk
:
order = get_object_or_404(Orders, pk=order_id)