Django注册表和注册独特的电子邮件表格

时间:2012-01-18 12:06:29

标签: django unique recaptcha django-registration

我目前正在使用django-registration v0.8a和django-recaptcha作为我的注册部分。除了我无法使RegistrationFormUniqueEmail工作外,一切正常,recaptcha字段显示出来。以下是一些细节。

我确保我的验证码\ forms.py确实是从正确的形式继承子类:

from registration.forms import RegistrationFormUniqueEmail

class RegistrationFormCaptcha(RegistrationFormUniqueEmail):
captcha = ReCaptchaField(attrs={'theme': 'white'})

我还将form_class键放在与处理调用的寄存器视图相关联的所有url中,例如:

url(r'^register/$',
          register,
          { 'form_class': RegistrationFormUniqueEmail,
                'backend': 'registration.backends.default.DefaultBackend' },
          name='registration_register'),

我注意到的一个奇怪的行为是,当我尝试更改表单上的标签时,更改没有被反映出来。也许这是我可能忽略了同样问题的一部分?

class RegistrationForm(forms.Form):
"""
Form for registering a new user account.

Validates that the requested username is not already in use, and
requires the password to be entered twice to catch typos.

Subclasses should feel free to add any additional validation they
need, but should avoid defining a ``save()`` method -- the actual
saving of collected user data is delegated to the active
registration backend.

"""
username = forms.RegexField(regex=r'^\w+$',
                            max_length=30,
                            widget=forms.TextInput(attrs=attrs_dict),
                            label=_("Username"),
                            error_messages={ 'invalid': _("This value must contain only letters, numbers and underscores.") })
email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict,
                                                           maxlength=75)),
                         label=_("Email address"))
password1 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False),
                            label=_("Password"))
password2 = forms.CharField(widget=forms.PasswordInput(attrs=attrs_dict, render_value=False),
                            label=_("Password (again)"))

即我将其中一个标签更改为另一个短语,不应该反映出来吗?

感谢您的观看!

1 个答案:

答案 0 :(得分:0)

我正在使用的解决方案是使用RegistrationFormCaptcha和RegistrationFormUniqueEmail创建表单,并将其与url中的captcha后端一起使用。

custom_registration / forms.py

from captcha.forms import RegistrationFormCaptcha
from registration.forms import RegistrationFormUniqueEmail


class RegistrationFormUniqueEmailRecaptcha(RegistrationFormUniqueEmail, RegistrationFormCaptcha):
    pass

urls.py

from custom_registration.forms import RegistrationFormUniqueEmailRecaptcha

    ...
    url(r'^w/accounts/register/$',
        'registration.views.register',
        {'backend': 'captcha.backends.default.DefaultBackend',
         'form_class': RegistrationFormUniqueEmailRecaptcha}),
    ....