就让我们来看看在source为两类显示:
class RegistrationFormTermsOfService(RegistrationForm):
"""
Subclass of ``RegistrationForm`` which adds a required checkbox
for agreeing to a site's Terms of Service.
"""
tos = forms.BooleanField(widget=forms.CheckboxInput,
label=_(u'I have read and agree to the Terms of Service'),
error_messages={'required': _("You must agree to the terms to register")})
class RegistrationFormUniqueEmail(RegistrationForm):
"""
Subclass of ``RegistrationForm`` which enforces uniqueness of
email addresses.
"""
def clean_email(self):
"""
Validate that the supplied email address is unique for the
site.
"""
if User.objects.filter(email__iexact=self.cleaned_data['email']):
raise forms.ValidationError(_("This email address is already in use. Please supply a different email address."))
return self.cleaned_data['email']
正如你可以看到这两个类不会覆盖由其他这样定义的方法,你应该能够只定义你自己的类作为:
from registration.forms import RegistrationFormUniqueEmail, RegistrationFormTermsOfService
class RegistrationFormTOSAndEmail(RegistrationFormUniqueEmail, RegistrationFormTermsOfService):
pass
它应该功能,但我没有测试过。至于在哪里放置这个班级; forms.py
是一个很好的位置。
更新:
在https://django-registration.readthedocs.org/en/latest/views.html小阅读,它告诉我们,我们可以通过视图通过URL定义一些参数;例如一个表单类。 只需使用像网址:
url(r'^register/$',
RegistrationView.as_view(form_class=RegistrationFormTOSAndEmail),
name='registration_register')
我将如何传递'RegistrationFormTOSAndEmail'到Django的注册提供的模板,而不是默认的? – user21398
我已经更新了答案。但通过搜索一次就可以轻松找到答案,无论是通过谷歌还是本网站。 – EWit
我认为可能有两件事情不在这里:它应该是url(r ^/accounts/register/$'而不是url(r'^ accounts /'),并且一定要在该条目之前放置该行:url r'^ accounts /',include('registration.backends.default.urls')), – eezis