【发布时间】:2016-12-12 12:38:37
【问题描述】:
这是我的 view.py 我正在尝试从支付网关获得响应 但是 m 得到 403 Forbidden CSRF 验证失败。请求中止。付款后,我为视图免除了 CSRF 令牌,但仍然显示相同的错误
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def resp(request, encResp):
print " RESPONSE WITH CSRF EXEMPT "
'''
Please put in the 32 bit alphanumeric key in quotes provided by CCAvenues.
'''
workingKey = WorkingKey
decResp = decrypt(encResp,workingKey)
data = '<table border=1 cellspacing=2 cellpadding=2><tr><td>'
data = data + decResp.replace('=','</td><td>')
data = data.replace('&','</td></tr><tr><td>')
data = data + '</td></tr></table>'
html = '''\
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Response Handler</title>
</head>
<body>
<center>
<font size="4" color="blue"><b>Response Page</b></font>
<br>
$response
</center>
<br>
</body>
</html>
'''
fin = Template(html).safe_substitute(response=data)
return HttpResponse(fin)
我在 stackoverflow 上阅读了许多解决方案并尝试过但仍然无法正确
我的主要 urls.py
url(r'^booked/', include('booking.urls')),
我在名为 booking
的应用中的 urls.pyurlpatterns = patterns('',
url(r'^responce-cc/', "booking.views.resp", name="cc_response_url"),)
我传递给支付网关的重定向网址是
https://www.mysitename.com/booked/responce-cc/
【问题讨论】:
-
使用@csrf_exempt,我认为您不会收到 CSRF 验证错误。你一定是在调用另一个视图。
-
不,我有正确的视图 url,但仍然得到相同的错误
-
仍然存在错误。也许发布您的整个 urlconf 和您正在调用的 URL?
-
我已为以下问题添加了 urls.py
-
我遇到了同样的问题,在另一个项目中再次出现,奇怪的是我只是在其他应用程序的视图(同一个项目)中粘贴了带有
csrf_exempt的视图并配置了网址,它工作了!!!跨度>
标签: python django django-1.9 ccavenue