django-laravel-validator,是一款 Django 的数据校验插件,目的是为了简化django开发中的数据校验问题,使用简单的 Laravel 校验语法,不与html绑定,如果你不喜欢 Django 的 form 框架,那么 django-laravel-validator 将是一个不错的选择.
用法示例:
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 = self.data.get('password') password_confirm = self.data.get('password_confirm') email = self.data.get('email') captcha_0 = self.data.get('captcha_0') captcha_1 = self.data.get('captcha_1') if not password == password_confirm: self.add_error(dict(pass_not_match=u'密码不匹配')) if User.objects.filter(email=email).exists(): self.add_error(dict(user_exists=u'该用户已存在')) try: CaptchaStore.objects.get(response=captcha_1, hashkey=captcha_0, expiration__gt=get_safe_now()).delete() except CaptchaStore.DoesNotExist: self.add_error(dict(captcha_error=u'验证码错误')) self.error_list.get('captcha_1').update(dict(captcha_error=u'验证码错误')) =