Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试使用API(支付网关集成)将Django连接到Payfort。当我运行pay.html时,它在我的视图文件中给了我一个值错误_Python_Django_Http_Render_Payfort - Fatal编程技术网

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

Python 尝试使用API(支付网关集成)将Django连接到Payfort。当我运行pay.html时,它在我的视图文件中给了我一个值错误,python,django,http,render,payfort,Python,Django,Http,Render,Payfort,错误为:ValueError:view hadid.views.initiate\u未返回HttpResponse对象。相反,它没有返回任何结果。 异常位置:C:\Users\Chaims music\AppData\Local\Programs\Python38\lib\site packages\django\core\handlers\base.py,在\u get\u response,第124行 我在下面添加我的def initiate_付款 def initiate_payment(

错误为:ValueError:view hadid.views.initiate\u未返回HttpResponse对象。相反,它没有返回任何结果。

异常位置:C:\Users\Chaims music\AppData\Local\Programs\Python38\lib\site packages\django\core\handlers\base.py,在\u get\u response,第124行

我在下面添加我的def initiate_付款

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()
这只是错误的来源。请帮忙,我已经试过了

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


非常感谢您的帮助。

您的视图必须返回一个响应,您在except块中返回render(…),但在try块中不返回任何内容。

我试图在try语句下面返回一些内容,但当我这样做时,会使我的(transaction=transaction.objects.create(made\u=user,amount=amount))行“无法访问”。我该怎么办?在返回之前,只需将事务代码放入try块中。