加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 为什么Google ReCaptcha不会阻止提交表单?

发布时间:2020-12-20 13:10:17 所属栏目:Python 来源:网络整理
导读:我使用 django-nocaptcha-recaptcha并遵循文档中的确切步骤: https://github.com/ImaginaryLandscape/django-nocaptcha-recaptcha 这是我的模板: {% extends 'base.html' %}{% block content %}div class="col-sm6 col-sm-offset-3" h1HastePaste/h1 form
我使用 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”设置中.任何帮助都会很棒!

编辑:对不起,如果我的问题不明确.不起作用意味着验证码显示,但它没有效果.即使未检查验证码,我也可以提交表单.

解决方法

我自己解决了这个问题. NoReCaptchaField不应该在Meta类中.它的工作方式如下:

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读