我想在 url 中获取当前的交易 id。应该是这样的
www.example.com/final_result/53432e1dd34b3
.
我写了以下代码,但付款成功后,我被重定向到 404 页。
(www.example.com/final_result//)
视图.py
@csrf_exempt
def pay_notif(request, v_transaction_id):
if request.method=='POST':
v_transaction_id=request.POST.get('transaction_id')
endpoint='https://testpay.com/?v_transaction_id={0}&type=json'
req=endpoint.format(v_transaction_id)
last_result=urlopen(req).read()
if 'Approved' in last_result:
session=Pay.objects.filter(session=request.session.session_key).latest('id')
else:
return HttpResponse(status=204)
return render_to_response('final.html',{'session':session},context_instance=RequestContext(request))
网址.py
url(r'^final_result/(?P<v_transaction_id>[-A-Za-z0-9_]+)/$', 'digiapp.views.pay_notif', name="pay_notif"),
模板:
<input type='hidden' name='v_merchant_id' value='{{newpayy.v_merchant_id}}' />
<input type='hidden' name='item_1' value='{{ newpayy.esell.up_name }}' />
<input type='hidden' name='description_1' value='{{ newpayy.esell.up_description }}' />
<input type='hidden' name='price_1' value='{{ newpayy.esell.up_price }}' />
#page to be redirected to after successful payment
<input type='hidden' name='success_url' value='http://127.0.0.1:8000/final_result/{{newpayy.v_transaction_id}}/' />
我该怎么办?