A laravel validator like django-use validator

django, validator, django-laravel-validator
pip install django-laravel-validator==0.1



1. what

django-laravel-validator is a django third party plugin of the purpose to validate input data easily, the easily means easy to validate , and easy to custom error message, the most import is easy to extend, the project is inspired by the validation system of Laravel , the most sexy php framework I ever use , she is sexy but she is also Fat, but i do not care fat.

2. why

I use Django framework since last year, i built some small apps, yap, it is fast to code ,but hard to use and understand, expecially the FORM system of django, i found it hard to validate and add custom error message, in some way you should hack the code to satisfied your logic, but in laravel, validate is more easy and helpful, so i copy the validate system of Laravel to django.

3. how


pip install django-laravel-validator

if you checkout from github or download the tarball

python install


you do not need to install the app to django's setting file. inface it is not a really django package, it is just a python package.

class RegistValidator(Validator):
    email = 'required|email'
	password = 'required|min:8'
    password_confirm = 'required|min:8'
    captcha_0 = 'required'
    captcha_1 = 'required'

    def check(self):
        password ='password')
        password_confirm ='password_confirm')
        email ='email')
        captcha_0 ='captcha_0')
        captcha_1 ='captcha_1')

        if not password == password_confirm:

        if User.objects.filter(email=email).exists():

            CaptchaStore.objects.get(response=captcha_1, hashkey=captcha_0, expiration__gt=get_safe_now()).delete()
        except CaptchaStore.DoesNotExist:

In your views:

error_message = {'email.required': u'邮箱地址不能为空'}
validator = RegistValidator(request.POST, message=error_message)
if validator.fails():
    # do what you want
    error = validator.errors()
# then deal with errors


REQUIRED # email = 'required'
NUMERIC # phone = 'numeric'
MIN # password = 'min:8'
MAX # email = 'max:16'
RANGE # email = 'range:8,16'
LENGTH # email = 'length:18'
ACCEPTED # remember_me = 'accepted' , should be 'yes' 'on' or '1'
ALPHA # username = 'ALPHA', should be alpha characters
EMAIL # email = 'required|email'
IP  # ipaddr = 'ip'  validate for ip
BOOL # confirm = 'bool' , should be 'True', 'False', '0', '1'
REGEX # complicated = 'regex:^[0-9A-Z]{10,20}$' , for validate a regex
MATCH # password_confirm = 'required|match:password', match a exists field
UNIQUE # email = 'required|unique:account.User,email' # parameter just the app and the model inside the app, then the model field.
JSON # json = 'json', match a json string, i use it for hstore data type.

And others:

i hate long and useless document, so just check the code for your purpose and fork it, and it just under my development

4. contribute

just make pull request or fork to your repos, and if you like, buy me a beer or a launch.


  1. i18n support for display error messages
  2. python3 compatible
  3. more userful validators support inside the package (long term)