我正在为django使用django-inspectional-registration模块。
我的问题是如何验证此模块中的默认电子邮件。
我尝试从RegistrationForm
继承并在raise ValidationError(_("The two email fields didn't match."))
方法中编辑clean(self)
中的文字:
from registration.forms import RegistrationForm
from registration.views import RegistrationView
from django.forms import ValidationError
from django.utils.translation import ugettext_lazy as _
class MyRegistrationForm(RegistrationForm):
def clean(self):
if 'email1' in self.cleaned_data and 'email2' in self.cleaned_data:
if self.cleaned_data['email1'] != self.cleaned_data['email2']:
raise ValidationError(_(
"My text"))
return self.cleaned_data
我也更改了网址:
url(r'^registration/register/$', RegistrationView.as_view(), {'form_class': MyRegistrationForm}, name='registration_register'),
url(r'^registration/', include('registration.urls')),
但是当我放入两封不同的电子邮件时,它仍然会显示错误的文字The two email fields didn't match.
UPD。现在我看到django-inspectional-registration没有参数来传递像django-registration这样的MyRegistrationForm。