在表单django-allauth app结尾处显示google recpatcha

时间:2017-08-08 17:37:59

标签: python django django-recaptcha

我正在使用django(1.10)allauth app创建一个注册表单。我从 - https://github.com/praekelt/django-recaptcha

安装了django-recaptcha应用程序

验证码正在运行,但它正在显示字段'组织'正如我在组织'之后给模块打电话一样。领域。有没有办法让字段在密码字段后显示在最后。

Forms.py

from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Field
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteField
from phonenumber_field.formfields  import PhoneNumberField
from . import models
from captcha.fields import ReCaptchaField


class SignUpForm(forms.Form):
    first_name = forms.CharField(max_length=30)
    last_name = forms.CharField(max_length=30)
    phone_number = PhoneNumberField(label=_("Phone (Please state your country code eg. +44)"))
    organisation = forms.CharField(max_length=50)
    captcha = ReCaptchaField(attrs={'theme' : 'clean'})

signup.html

{% extends "account/base.html" %}

{% load i18n crispy_forms_tags %}

{% block head_title %}{% trans "Signup" %}{% endblock %}

{% block content %}
<h1>{% trans "Sign Up" %}</h1>

<p>{% blocktrans %}Already have an account? Then please <a href="{{ login_url }}">sign in</a>.{% endblocktrans %}</p>

<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
  {% csrf_token %}
  {{ form|crispy }}
  {% if redirect_field_value %}
  <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
  {% endif %}

  <button class="btn btn-success" type="submit">{% trans "Sign Up" %} <span class="fa fa-chevron-right"></span></button>
</form>

{% endblock %}

SO参考 - Is there any solutions to add captcha to Django-allauth?

截图 -

enter image description here

验证码需要再次输入密码&#39;领域。我需要创建子类或类似的东西吗?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我必须以这种方式覆盖默认的

class SignUpForm(forms.Form):
    first_name = forms.CharField(max_length=30)
    last_name = forms.CharField(max_length=30)
    phone_number = PhoneNumberField(label=_("Phone (Please state your country code eg. +44)"))
    organisation = forms.CharField(max_length=50)
    email = forms.EmailField()
    password1 = forms.CharField(max_length=20)
    password2 = forms.CharField(max_length=20)
    captcha = ReCaptchaField(attrs={'theme' : 'clean'})

可能这不是最好的方式,但暂时缓解。欢迎任何建议。