【问题标题】:Why does Google ReCaptcha not prevent the submission of the form?为什么 Google ReCaptcha 不阻止提交表单?
【发布时间】:2016-06-08 12:59:55
【问题描述】:

我使用 django-nocaptcha-recaptcha 并遵循文档中的确切步骤:https://github.com/ImaginaryLandscape/django-nocaptcha-recaptcha

这是我的模板:

{% extends 'base.html' %}

{% block content %}
<div class="col-sm6 col-sm-offset-3">
    <h1>HastePaste</h1>
    <form method="POST" action=""> {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" class="btn btn-default">
        <div class="g-recaptcha" data-sitekey="6LfimBYTAAAAANXrMzDUVTiUHAm7ZaN2AR1Qs2SG"></div>
    </form>
</div>

{% endblock %}

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

在 base.html 中。

我的表格:

from django import forms
from nocaptcha_recaptcha.fields import NoReCaptchaField
from posts.models import Post


class PostForm(forms.ModelForm):
class Meta:
    model = Post
    fields = '__all__'
    captcha = NoReCaptchaField()

公钥和密钥在设置中以及已安装应用程序中的“nocaptcha_recaptcha”中。任何帮助都会很棒!

编辑:对不起,如果我的问题不清楚。不起作用意味着验证码出现了,但没有效果。即使未选中验证码,我也可以提交表单。

【问题讨论】:

  • “不起作用”以及它如何不起作用,正在发生什么,您希望发生什么。有没有错误?
  • @Risadinha 我编辑了我的帖子
  • 也许你想要这个检查一下stackoverflow.com/a/29553829/7337499

标签: python django forms recaptcha


【解决方案1】:

我自己解决了这个问题。 NoReCaptchaField 不应在 Meta 类中。它是这样工作的:

class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = '__all__'
    captcha = NoReCaptchaField()

不,如果验证码被忽略,我会收到一条错误消息,但我猜这是一个不同的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-13
    • 2023-03-19
    • 2014-04-22
    • 2012-02-02
    • 2016-03-12
    • 2018-11-07
    • 2020-10-06
    • 2017-02-10
    相关资源
    最近更新 更多