2016-12-12 188 views
3

這是我的view.py我試圖從支付網關獲得響應 但得到403禁止CSRF驗證失敗。請求中止。後付款免徵我CSRF令牌的觀點,但仍然顯示了同樣的錯誤Django CSRF驗證失敗。即使使用@csrf_exempt也終止請求

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) 

我讀了許多計算器解決方案和嘗試,但不能仍然得到它的權利

我的主要urls.py

url(r'^booked/', include('booking.urls')), 

我在app urls.py命名預訂

urlpatterns = patterns('', 
url(r'^responce-cc/', "booking.views.resp", name="cc_response_url"),) 

和重定向URL我傳遞給支付網關是

https://www.mysitename.com/booked/responce-cc/ 
+0

與@csrf_exempt,我不認爲你可以得到一個CSRF驗證錯誤。你必須以某種方式調用另一種觀點。 – RemcoGerlich

+0

不,我有正確的視圖網址,但仍然得到相同的錯誤 – Bijoy

+0

仍然錯誤是在某處。也許發佈你的整個urlconf和你打的網址? – RemcoGerlich

回答

-1

添加{% csrf_token %}某處體之間。

+0

我無法添加令牌,回覆是從支付網關生成的 – Bijoy

0
from ccavutil import encrypt,decrypt 
from string import Template 
from django.http import HttpResponse 

def res(encResp): 
''' 
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) 

使用上面的代碼中有一步到位! :)

+0

它與我寫的代碼相同,也是我導入了Template,HttpResponse和encrypt,解密。 – Bijoy

相關問題