views:

29

answers:

1

I am trying to use validators in my form fields but am getting an error:

from django import forms
from django.db import models
from django.core.exceptions import ValidationError


class Register(forms.Form):
    username = forms.CharField(max_length=100,label="Username",validators=[validate_email])

>>>> name 'validate_email' is not defined

I have tried this with a number of different validator types, only to be hit with the same message for each. I have looked over the documentation and really can't see what I am missing as to how to import the validators into the class, any advice is appreciated

+2  A: 

You seem to be missing an import. Try adding

from django.core.validators import validate_email

to your imports

Aurojit Panda
Thanks, ok that makes sense.... just in the django docs I don't think its clear that you are supposed to import it this way so I was wondering about that, I am sure its mentioned somewhere else, just I was looking at: http://docs.djangoproject.com/en/1.2/ref/validators/
Rick