RegisterForm(forms.Form)类: 用户名= Forms.CharField(max_length = 35,label =“用户名 eintragen”) 密码= Forms.CharField(最小长度= 6,最大长度= 50,标签=“密码eintragen”,小部件= forms.PasswordInput) email = forms.EmailField(label =“电子邮件eintragen”)
def clean_username(self):
username = self.cleaned_data["username"]
if User.objects.filter(username__iexect=username).exists():
raise forms.ValidationError("Diesen Usernamen gibt es schon")
return username
CharField不受支持的查询'iexect'或不允许在字段上加入。