属性错误:“str”对象没有属性“post”

时间:2021-03-17 07:23:27

标签: python django django-views payment-gateway razorpay

我是 Django 的新手,尝试将 razorpay 与我的网站集成,但出现错误

AttributeError: 'str' 对象没有属性 'post'

views.py

def order(request, id):
    product = Product.objects.get(prod_ID=id)
    if request.method == 'POST':
        customer_id = request.user
        product = Product.objects.get(prod_ID=id)
        product_id = product
        try:
            quantity = request.POST['quantity']
            quantity = int(quantity)
            order_price = quantity * product.prod_Price
            print(order_price)
        except MultiValueDictKeyError:
            pass

        try:
            size = request.POST['size']
            value.update(size=size)
        except MultiValueDictKeyError:
            pass

        try:
            Colour = request.POST['Color']
            value.update(Colour=Colour)
        except MultiValueDictKeyError:
            pass

        attribute_value = json.dumps(value)

        order_store = Order(user_id=customer_id, prod_id=product_id, quantity=quantity, 
        attribute_value=attribute_value,
                            order_price=order_price)
        if order_store:
            order_store.save()
            o_id = Order.objects.get(order_id=order_store.order_id)
            payment_store = Payment(order_id=o_id)
            payment_store.save()
            client = razorpay.Client('rzp_test_Cut6mUJgrjfQU', 'LSNlrKrH0NoUq8Y9rEUbg27')
            print(client)
            data = {
                'amount': order_price * 100,
                'currency': "INR",
                'receipt': 'Order for ' + str(o_id.order_id),
                'notes': {
                    'name': o_id.user_id.first_name + o_id.user_id.last_name,
                    'Payment_for': o_id.prod_id.prod_Name
                }
            }
            print(data)
            order_detail = client.order.create(data=data)
            print(order_detail)
            return render(request, 'user/payment.html', {'order_store': order_store})
    context = {'products': products
               }

    return render(request, 'user/order.html', context)

在这里,我正在尝试将付款与我的网站集成,但在创建订单和付款状态后,我正在尝试付款,但我不知道我做错了什么。

error1

error2

1 个答案:

答案 0 :(得分:2)

要初始化客户端,您必须使用 auth 参数 - 请参阅 razorpay Initialization

并给出一个 tuple 作为值:

import razorpay
client = razorpay.Client(auth=("<YOUR_KEY>", "<YOUR_SECRET>"))