Почему View возвращает None при переходе на страницу оплаты в Django?

Остальная часть приложения работает хорошо, но возникает проблема, когда я перехожу на страницу оплаты, приложение возвращает None. Я не могу понять, где ошибка.

Это payment_page.html, ошибка возникает, когда я пытаюсь получить доступ к этой странице

Это метод оплаты в представлении, он не может вернуть объект HttpResponse, вместо этого он возвращает None.


# Method for processing payments
def payment_method_page(request):
    current_customer = request.user.customer
    
    #Remove existing card
    if request.method == "POST":
        stripe.PaymentMethod.detach(current_customer.stripe_payment_method_id)
        current_customer.stripe_payment_method_id = ""
        current_customer.stripe_card_last4= ""
        current_customer.save()
        return redirect(reverse('customer:payment_method'))
        
    #Save Stripe customer info
    if not current_customer.stripe_customer_id:
        customer = stripe.Customer.create()
        current_customer.stripe_customer_id = customer['id']
        current_customer.save()
        
    #GEt Stripe payment method
    stripe_payment_methods = stripe.PaymentMethod.list(
        customer = current_customer.stripe_customer_id,
        type = "card",
    )
    print(stripe_payment_methods)
    
    if stripe_payment_methods and len(stripe_payment_methods.data) > 0:
        payment_method = stripe_payment_methods.data[0]
        current_customer.stripe_payment_method_id = payment_method.id
        current_customer.stripe_card_last4 = payment_method.card.last4
        current_customer.save()
    
    else: 
         current_customer.stripe_payment_method_id = ""
         current_customer.stripe_card_last4 = ""
         current_customer.save()
    
    if not current_customer.stripe_payment_method_id:
        
        intent = stripe.SetupIntent.create(
            customer  = current_customer.stripe_customer_id
        )
        return render(request, 'customer/payment_method.html', {
            "client_secret": intent.client_secret,
            "STRIPE_API_PUBLIC_KEY": settings.STRIPE_API_PUBLIC_KEY
        })
    else:
        render(request, 'customer/payment_method.html')


Я думаю, что render(request, 'customer/payment_method.html') (последняя строка вашего представления) является здесь виновником. Возможно, вам следует использовать return render(request, 'customer/payment_method.html') для решения проблемы.

Вернуться на верх