Django: unable to read POST parameters sent by payment gateway

前端 未结 2 1749
旧时难觅i
旧时难觅i 2021-01-28 05:33

I am unable to read POST parameters sent by payment gateway after payment was processed. Payment gateway redirects to returnUrl (I pass this to payment gateway befo

相关标签:
2条回答
  • 2021-01-28 05:56

    APPEND_SLASH shouldn't matter, as it only affects URLs that cannot be found, but you are explicitly specifying a URL pattern without a slash. So the issue is with your path definition.

    Assuming we are talking about the main, project-level urls.py, the correct setting would be:

    path('cashfreeresponse',views.cashfree_response, name='cashfree_response'),
    returnUrl = 'http://127.0.0.1:8000/cashfreeresponse'
    

    But my guess is that your path named cashfree_response is defined in an app (e.g. polls/urls.py) and that it is included at a subpath in the project-level (e.g. mysite/urls) like that:

    path('polls/', include('polls.urls')),
    

    In that case, the correct returnUrl would be http://127.0.0.1:8000/polls/cashfreeresponse.

    Instead of hard-coding the URL, you can use reverse together with request.

    from django.urls import reverse
    request.build_absolute_uri(reverse('cashfreeresponse')
    

    Note: You might have to use reverse('<appname>:cashfreeresponse') here, e.g. reverse('polls:cashfreeresponse')

    Edit: from your update, it seems like you still have a trailing slash in the path definition:

        path('cashfreeresponse/',views.cashfree_response, name='cashfree_response'),
    

    Change that to:

        path('cashfreeresponse',views.cashfree_response, name='cashfree_response'),
    
    0 讨论(0)
  • 2021-01-28 06:01

    @login_required decorator was causing the issue. I think @login_required redirecting the page to see if user logged in (even if user already logged in) then redirecting back to this view. During this process, it is loosing POST data and converting the request method to GET.

    0 讨论(0)
提交回复
热议问题