有什么解决方案可以将验证码添加到Django-allauth中吗? [英] Is there any solutions to add captcha to Django-allauth?

查看:126
本文介绍了有什么解决方案可以将验证码添加到Django-allauth中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么解决方案可以将验证码与django-allauth结合使用?
我想在注册表格上使用验证码进行标准的电子邮件和密码注册。

Is there any solutions to use captcha with django-allauth? I want to use captcha on registration form for standard email+password registrations.

推荐答案

我也需要使用django-allauth进行此操作,发现实现了 django-recaptcha 包相对简单。

I too needed to do this with django-allauth and found that implementing the django-recaptcha package to be relatively simple.

注册一个验证码帐户

将设置插入

# settings.py

RECAPTCHA_PUBLIC_KEY = 'xyz'
RECAPTCHA_PRIVATE_KEY = 'xyz'

RECAPTCHA_USE_SSL = True     # Defaults to False



自定义SignupForm



在安装django-recaptcha之后,我跟随了一些指南时自定义用户配置文件以自定义SignupForm。

Customize SignupForm

After installing django-recaptcha, I followed someguidelines for customizing the SignupForm.

from django import forms
from captcha.fields import ReCaptchaField

class AllauthSignupForm(forms.Form):

    captcha = ReCaptchaField()

    def save(self, request, user):
        user = super(AllauthSignupForm, self).save(request)
        return user

您还需要在设置中告诉allauth从此表单继承.py

You also need to tell allauth to inherit from this form in settings.py

ACCOUNT_SIGNUP_FORM_CLASS = 'myapp.forms.AllauthSignupForm'



连接注册表单模板



{{form.captcha}} {{form.captcha.errors}} 应该在注册模板上下文中可用。

Wire up signup form template

{{ form.captcha }} and {{ form.captcha.errors }} should be available on the signup template context at this point.

就是这样!似乎所有的验证逻辑都包含在 ReCaptchaField 中。

That was it! Seems like all the validation logic is tucked into the ReCaptchaField.

这篇关于有什么解决方案可以将验证码添加到Django-allauth中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆