当我在网站上添加Recaptcha时,出现此错误:
TypeError at /accounts/register
'QueryDict' object is not callable
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register
Django Version: 2.2
Exception Type: TypeError
Exception Value:
'QueryDict' object is not callable
Exception Location: D:\Learning\Work\Djngo\todo_app\todo\views.py in signup, line 24
Python Executable: C:\Users\Lenovo\AppData\Local\Programs\Python\Python37-32\python.exe
Python Version: 3.7.0
Python Path:
['D:\\Learning\\Work\\Djngo\\todo_app',
'C:\\Users\\Lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
'C:\\Users\\Lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
'C:\\Users\\Lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
'C:\\Users\\Lenovo\\AppData\\Local\\Programs\\Python\\Python37-32',
'C:\\Users\\Lenovo\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages']
Server time: Tue, 3 Dec 2019 08:58:29 +0000
但是我不知道该如何解决。
这是我的 views.py
def signup(requests):
###############################
if requests.method == 'POST':
reg = register(requests.POST)
############
clientKey = requests.POST['g-recaptcha-response']
secretKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
captchaData = {
'secret': secretKey,
'response': clientKey
}
r = requests.post('https://www.google.com/recaptcha/api/siteverify', data=captchaData)
response = json.loads(r.text)
verify = response['success']
print('Result: ' + verify)
if reg.is_valid():
user = reg.save(commit=False)
user.set_password(User)
user.save()
messages.success(request, 'You Are SuccessFully Registerd!')
else:
print(reg.errors)
else:
reg = register()
return render(requests,'signup.html',{'reg':reg,})
任何帮助将不胜感激!
谢谢!