当我尝试通过recaptcha验证我的时候,为什么会出现这个错误?

时间:2016-02-26 14:02:41

标签: python django django-views 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.

我希望没有必要的信息,我忘记了。任何帮助将不胜感激

2 个答案:

答案 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())