appengine:如何在中使用验证器类别:财产?

2024-04-29 08:08:03 发布

您现在位置:Python中文网/ 问答频道 /正文

http://code.google.com/intl/en/appengine/docs/python/datastore/propertyclass.html#Property中描述

但是没有示例代码。在

我的代码如下:

class Model(db.Model):
  email = db.EmailProperty(validator=clean_email)

  def clean_email(self,value):
    if ...

Tags: 代码cleancomhttpdocsdbmodelemail
2条回答
class Model(db.Model):

  def clean_email(value):
    if ...

  email = db.EmailProperty(validator=clean_email)

使用参数。在这个例子中,论点本身就是email的价值。在

您需要在属性之前定义方法,如joetsuihk所示,或者在类之外将其定义为函数。我推荐后者,因为没有理由让验证器与类关联。在

相关问题 更多 >