尝试使用 API 将 Django 连接到 Payfort。(支付网关集成)。当我 运行 pay.html 它在我的视图文件中给我一个值错误

Trying to connect Django to Payfort with an API .(Payment gateway integration). when i run the pay.html it gives me a value error in my views file

错误是:ValueError:视图 hadid.views.initiate_payment 没有 return HttpResponse 对象。它 return 改为 None。

异常位置:C:\Users\Chaims music\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py in _get_response, line 124

我在下面添加我的定义initiate_payment

def initiate_payment(request):
if request.method == "GET":
    return render(request, 'templates/pay.html')
 try:
    username = request.POST['username']
    password = request.POST['password']
    amount = int(request.POST['amount'])
    user = authenticate(request, username=username, password=password)
    if user is None:
        raise ValueError
    auth_login(request=request, user=user)
except:
    return render(request, 'templates/pay.html', context={'error': 'Wrong Account Details or amount'})

transaction = Transaction.objects.create(made_by=user, amount=amount)
transaction.save()

这只是 initiate_payment 错误的来源。请帮忙我已经试过了

如果需要任何其他文件,请告诉我。

感谢任何帮助。

你的视图必须 return 一个响应,你 return 在你的 except 块中渲染(...)但你没有 return 在 try 块中的任何东西