我收到错误:“str”对象没有属性“method”。请参阅下面的代码:
@csrf_exempt
def completepayment(request):
varerr =''
plist = []
if request.method == 'POST':
try:
nid = request.POST['txnref']
except MultiValueDictKeyError:
varerr ="Woops! Operation failed due to server error. Please try again later."
return render(request, 'uportal/main.html', {'varerr':varerr})
# Fetching member details
trym = Transactions.objects.get(TransRef=nid)
amount = trym.Amount
famt = int(amount * 100)
product_id = 48
salt = '4E6047F9E7FDA5638D29FD'
hash_object = hashlib.sha512(str(product_id)+str(nid)+str(famt))
hashed = hash_object.hexdigest()
url = 'https://bestng.com/api/v1/gettransaction.json?productid=pdid&transactionreference=nid&amount=famt'
raw = urllib.urlopen(url)
js = raw.readlines()
#js_object = simplejson.loads(js)
res = simplejson.dumps(js)
for item in res:
rcode = item[0]
#rdesc = item[1]
#preff = item[2]
thisresp = completepayment(rcode)
plist.append(thisresp)
else:
varerr ="Woops! Operation failed due to server error. Please try again later."
return render(request, 'uportal/main.html', {'plist':plist, 'varerr':varerr, 'completepayment':'completepayment'})
总之,我尝试从外部API接受和使用httppost值。值在我检查元素时显示,但DJANGO没有检索。请帮忙。在
这是我的网址.py在
^{pr2}$谢谢你
您的问题似乎是请求是str对象而不是请求对象。在
请出示网址.py以及视图.py. 在
为了可读性,我们重写以下部分:
或者甚至是这样:
^{pr2}$另外,try块不是我要使用的。相反,我将使用POST dict的get方法并返回一个标志值:
我无法重现你得到的错误。项目级别略有不同网址.py(非常简单),“completepayment”视图对我来说很好。给你网址.py. 在
相关问题 更多 >
编程相关推荐