我使用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.
我希望没有必要的信息,我忘记了。任何帮助将不胜感激
答案 0 :(得分:1)
我点击之后发送解决方案发生在我身上。我只需要返回home.html的渲染,以防表单无效。对不必要的帖子抱歉!
答案 1 :(得分:1)
当form.is_valid()
为False
时,您不会回复。
尝试添加:
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())