/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

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)