--
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: pyth...@googlegroups.com
详情: http://code.google.com/p/cpyug/wiki/CpyUg
G+: https://plus.google.com/u/0/communities/108786798869709602787
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛的“python-cn(华蟒用户组,CPyUG 邮件列表)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 python-cn+...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
--
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: pyth...@googlegroups.com
详情: http://code.google.com/p/cpyug/wiki/CpyUg
G+: https://plus.google.com/u/0/communities/108786798869709602787
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛的“python-cn(华蟒用户组,CPyUG 邮件列表)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 python-cn+...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
--
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: pyth...@googlegroups.com
详情: http://code.google.com/p/cpyug/wiki/CpyUg
G+: https://plus.google.com/u/0/communities/108786798869709602787
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛的“python-cn(华蟒用户组,CPyUG 邮件列表)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 python-cn+...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
用WTforms不好?我也用flask,不管前台js怎么验证,后台拿wtforms挡一下就成了。在orm层做验证,没什么必要吧?
class Validator(object): "注意多个此验证类的实例作用的类的多个实例,共享同一个验证方法,及参数,及配置" def __init__(self,attr, validate_func,**kwargs): self.attr = attr self.validate_func = validate_func self.error_code = kwargs.pop('error_code',400) self.kwargs = kwargs
def __get__(self, instance, owner): if instance is None: return getattr(owner,self.attr) return getattr(instance,self.attr)
def __set__(self, instance, value): real_attr = self.attr old_value = getattr(instance, real_attr) if old_value == value: return if self.kwargs: val,err = self.validate_func(value) else: val, err = self.validate_func(value,**self.kwargs) if err: log.debug("INVALID {}:{}".format(self.attr,value)) raise ValidateError(err, self.error_code, self.attr) elif old_value != val: setattr(instance, real_attr, val) _name = db.Column('name', db.String(255), nullable=False)
name = Validator('_name',validator.str_to_python,min_length=2,max_length=255,empty=False)
借地问一下,我post是一个json,Content-Type是application/json原本是想用json schema验证的,后来发现基本不可能前,因为所有request和response的结构都是动态的,还有属性依赖其他属性的存在与否或其他属性的值的情况。
现在我全部都是if结构做的验搞的挺痛苦得,难到不难,就是代码写的超麻烦,不清晰,有人有什么好办法么?
--
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: pyth...@googlegroups.com
详情: http://code.google.com/p/cpyug/wiki/CpyUg
G+: https://plus.google.com/u/0/communities/108786798869709602787
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛的“python-cn(华蟒用户组,CPyUG 邮件列表)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 python-cn+...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
--BR,/Catstyle_Lee
--
--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
发言: pyth...@googlegroups.com
详情: http://code.google.com/p/cpyug/wiki/CpyUg
G+: https://plus.google.com/u/0/communities/108786798869709602787
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了 Google 网上论坛的“python-cn(华蟒用户组,CPyUG 邮件列表)”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 python-cn+...@googlegroups.com。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。