Tôi có một hình thức khá đơn giản:Tuỳ chỉnh hình thức xác nhận
from django import forms
class InitialSignupForm(forms.Form):
email = forms.EmailField()
password = forms.CharField(max_length=255, widget = forms.PasswordInput)
password_repeat = forms.CharField(max_length=255, widget = forms.PasswordInput)
def clean_message(self):
email = self.clean_data.get('email', '')
password = self.clean_data.get('password', '')
password_repeat = self.clean_data.get('password_repeat', '')
try:
User.objects.get(email_address = email)
raise forms.ValidationError("Email taken.")
except User.DoesNotExist:
pass
if password != password_repeat:
raise forms.ValidationError("The passwords don't match.")
Đây có phải là cách tùy chỉnh hình thức xác nhận được thực hiện? Tôi cần đánh giá trên email
rằng không có người dùng nào hiện đang tồn tại với địa chỉ email đó. Tôi cũng cần đánh giá rằng password
và password_repeat
phù hợp. Làm thế nào tôi có thể đi về việc này?
tôi thích làm xác nhận trên mothel hơn là trên hình thức: http://beutil.blogspot.com/2011/10/django-moving- business-rules-from-views.html – danihp