1👍
You can raise forms.ValidationError in forms.py
Here is an example:
class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput())
def clean_username(self):
username = self.cleaned_data.get("username")
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise forms.ValidationError("Are you sure you are registered? We cannot find this user.")
return username
Source:stackexchange.com