Django注册表格和注册唯一的电子邮件表单 [英] Django registration form and registration unique email form

查看:264
本文介绍了Django注册表格和注册唯一的电子邮件表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently using django-registration v0.8a and django-recaptcha for my registration portion. Everything is working fine with the recaptcha field showing up except that I am unable to get the RegistrationFormUniqueEmail to work. Here are some of the details.

我确保我的验证码正确地从正确的格式分类:

I have ensured that my captcha\forms.py is indeed subclassing from the correct form:

from registration.forms import RegistrationFormUniqueEmail

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

我还将form_class键放在与注册表视图关联的所有URL中它处理电话,例如:

I have also placed the form_class key in all the urls associated with the register view which handles the call, for instance:

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

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

One strange behaviour I have noticed is that when I attempt to change the labels on my forms, the changes are not being reflected. Perhaps this is part of the same problem as I might have overlooked something?

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)"))

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

i.e I change one of the labels to another phrase, shouldn't that be reflected?

感谢观看!

推荐答案

我使用的解决方案是使用RegistrationFormCaptcha和RegistrationFormUniqueEmail创建一个表单,并将其与网址中的验证码后端一起使用。

The solution I'm using is to create a form using RegistrationFormCaptcha and RegistrationFormUniqueEmail and use it with the captcha backend in urls.

custom_registration / forms.py

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}),
    ....

这篇关于Django注册表格和注册唯一的电子邮件表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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