django-laravel-validator Django 数据校验插件

我要开发同款
匿名用户2015年03月30日
37阅读
开发技术Python
所属分类Web应用开发、网页组件
授权协议MIT

作品详情

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'验证码错误'))=
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论