当我尝试通过 recaptcha 验证我的发件人时,为什么会出现此值错误?
Why do I get this valueerror when I try to validate my from via recaptcha?
我使用 django-nocaptcha-recaptcha 并遵循文档中的确切步骤:https://github.com/ImaginaryLandscape/django-nocaptcha-recaptcha
这是我的观点:
def home(request):
if request.method == 'POST':
form = PostForm(request.POST or None)
if form.is_valid():
save_it = form.save(commit=False)
save_it.save()
return HttpResponseRedirect(reverse(view, args=(save_it.pk,)))
else:
form = PostForm(request.POST or None)
return render(request, "home.html", locals())
我在提交表单时收到此错误消息,但 recaptcha 仍未选中:
The view posts.views.home didn't return an HttpResponse object. It returned None instead.
希望没有忘记的必要信息。任何帮助将不胜感激
单击“发送”后,我立即想到了解决方案。我只需要 return 呈现 home.html 以防表单无效。对不起,不必要的 post!
当您的 form.is_valid()
是 False
时,您不会 return 回复。
尝试添加:
def home(request):
if request.method == 'POST':
form = PostForm(request.POST or None)
if form.is_valid():
save_it = form.save(commit=False)
save_it.save()
return HttpResponseRedirect(reverse(view, args=(save_it.pk,)))
else:
return render(request, "home.html", locals()) # new line
else:
form = PostForm(request.POST or None)
return render(request, "home.html", locals())
我使用 django-nocaptcha-recaptcha 并遵循文档中的确切步骤:https://github.com/ImaginaryLandscape/django-nocaptcha-recaptcha
这是我的观点:
def home(request):
if request.method == 'POST':
form = PostForm(request.POST or None)
if form.is_valid():
save_it = form.save(commit=False)
save_it.save()
return HttpResponseRedirect(reverse(view, args=(save_it.pk,)))
else:
form = PostForm(request.POST or None)
return render(request, "home.html", locals())
我在提交表单时收到此错误消息,但 recaptcha 仍未选中:
The view posts.views.home didn't return an HttpResponse object. It returned None instead.
希望没有忘记的必要信息。任何帮助将不胜感激
单击“发送”后,我立即想到了解决方案。我只需要 return 呈现 home.html 以防表单无效。对不起,不必要的 post!
当您的 form.is_valid()
是 False
时,您不会 return 回复。
尝试添加:
def home(request):
if request.method == 'POST':
form = PostForm(request.POST or None)
if form.is_valid():
save_it = form.save(commit=False)
save_it.save()
return HttpResponseRedirect(reverse(view, args=(save_it.pk,)))
else:
return render(request, "home.html", locals()) # new line
else:
form = PostForm(request.POST or None)
return render(request, "home.html", locals())