Django:如何删除引发ValidationError出现的列表

时间:2017-05-23 02:05:51

标签: python django validation web error-handling

我想提出验证错误,以便红色框出现在下图中,但我不希望列表出现。似乎forms.ValidationError("")强制您输入一些文本,以便它可以出现在此错误列表中,但我已经使用{% if form.errors %}在我的.html中处理了该文本(显示红色框)。有没有办法阻止此列表出现?

ValidationError

class LoginForm(forms.Form): 
    username = forms.CharField(label='', widget=forms.TextInput 
               (attrs={'placeholder': 'Username or Email', 'class': 'login-field'})) 
    password = forms.CharField(label='', widget=forms.PasswordInput 
               (attrs={'placeholder': 'Password', 'class': 'login-field'})) 

    def clean(self): 
    username = self.cleaned_data.get('username') 
    password = self.cleaned_data.get('password') 
    user = authenticate(username=username, password=password) 
    if not user or not user.is_active: 
        raise forms.ValidationError("") 
    return self.cleaned_data 

    def login(self, request): 
        username = self.cleaned_data.get('username') 
        password = self.cleaned_data.get('password') 
        user = authenticate(username=username, password=password) 
        return user

0 个答案:

没有答案