我有一个测试.py文件,它应该发送一个POST请求到我的LocalHost站点(如果LH对此不起作用,我也可以对它进行测试)test.domain.com网站). 但是,我没有得到任何新的信息保存在我的数据库。我用GET-before试用过,效果很好。你知道吗
命令中的错误消息:
File "C:\Users\winkl\Desktop\VE\mysite\payment\views.py", line 36, in webhook user = User.objects.POST(id=request.POST('clientAccnum')) AttributeError: 'UserManager' object has no attribute 'POST'
你知道吗视图.py你知道吗
@csrf_exempt
def webhook(request):
template_name = 'payment/index.html'
hook = Webhook()
#ERROR MESSAGE FOR LINE BELOW
user = User.objects.POST(id=request.POST('clientAccnum'))
hook.user = user
hook.clientSubacc = request.POST('clientSubacc')
hook.eventType = request.POST('eventType')
hook.eventGroupType = request.POST('eventGroupType')
hook.subscriptionId = request.POST('subscriptionId')
hook.timestamp = request.POST('timestamp')
hook.timestamplocal = timezone.now()
hook.save()
user = User.objects.POST(id=request.POST('clientAccnum'))
hook.user = user
hook.user.profile.account_paid = hook.eventType == 'RenewalSuccess'
hook.user.profile.save()
print (hook.user, hook.clientSubacc, hook.timestamplocal)
return render(request, template_name)
你知道吗测试.py你知道吗
from django.test import TestCase
import requests
import json
url = 'http://127.0.0.1:8000/payment/webhook/'
data = {'user':'11',
'clientSubacc': '1111',
'eventType': 'RenewalSuccess',
'eventGroupType': 'Success',
'subscriptionId': '12345'}
r = requests.post(url, (data))
目标是让这个测试帖子创建一个成功的webhook,它将被保存在我的DB中。此信息更新我的用户帐户状态。你知道吗
重构或smth时出现错误类型。尝试使用
获取请求的用户
添加到答案
这个答案让我更接近,但并没有100%解决问题。你知道吗
最好打印整个帖子,而不是只打印用户。帮助我认识到第二个问题。你知道吗
我一直被困在这上面!谢谢你的帮助。你让我再往前走了几步,这就把我带到了其他地方。你知道吗
相关问题 更多 >
编程相关推荐