是否有任何解决方案可以将验证码添加到Django-allauth?

Ant*_*nio 4 captcha django-allauth

是否有任何解决方案使用验证码与django-allauth?我想在注册表上使用验证码进行标准电子邮件+密码注册.

scv*_*vnc 23

我也需要用django-allauth来做这件事,并发现实现django-recaptcha包相对简单.

配置django-recaptcha

注册一个recaptcha帐户.

插入你的设置

# settings.py

RECAPTCHA_PUBLIC_KEY = 'xyz'
RECAPTCHA_PRIVATE_KEY = 'xyz'

RECAPTCHA_USE_SSL = True     # Defaults to False
Run Code Online (Sandbox Code Playgroud)

自定义SignupForm

在安装了django-recaptcha之后,我遵循了一些(看似过时的)自定义SignupForm的指南.

from django import forms
from captcha.fields import ReCaptchaField

class AllauthSignupForm(forms.Form):

    captcha = ReCaptchaField()

    def signup(self, request, user):
        """ Required, or else it throws deprecation warnings """
        pass
Run Code Online (Sandbox Code Playgroud)

您还需要告诉allauth从settings.py中的此表单继承

ACCOUNT_SIGNUP_FORM_CLASS = 'myapp.forms.AllauthSignupForm'
Run Code Online (Sandbox Code Playgroud)

连接注册表单模板

{{ form.captcha }}并且此时{{ form.captcha.errors }}应该可以在注册模板上下文中使用.

就是这样!似乎所有的验证逻辑都隐藏在了ReCaptchaField.