3

我正在使用 django(1.10) allauth app 创建一个注册表单。我已经从 - https://github.com/praekelt/django-recaptcha安装了 django-recaptcha 应用程序

验证码正在工作,但它显示在“组织”字段之后,因为我在“组织”字段之后调用模块。有什么办法可以使该字段显示在密码字段之后的末尾。

表格.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'})

注册.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参考——是否有任何解决方案可以将验证码添加到Django-allauth?

截屏 -

在此处输入图像描述

验证码需要放在“再次输入密码”字段之后。我需要创建子类或类似的东西吗?

非常感谢任何帮助。

4

1 回答 1

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'})

可能这不是最好的方法,而是暂时的解脱。请任何建议都受到高度欢迎。

于 2017-08-08T19:52:55.180 回答