【问题标题】:How to retrieve the email from gae datastore?如何从 gae 数据存储中检索电子邮件?
【发布时间】:2013-03-27 10:48:54
【问题描述】:

我开始使用 google 数据存储和 jinja2。我可以添加和检索字符串值,但是当我使用 email 属性时: 电子邮件=db.电子邮件 并使用 .email 检索它,我得到 来自数据存储区的“google.appengine.api.datastore_types.Email”类。 我如何获得电子邮件的价值?

【问题讨论】:

    标签: google-cloud-datastore


    【解决方案1】:

    使用 .email 对我有用。

    python 代码

    import webapp2
    from google.appengine.ext import db
    
    class Greeting(db.Model):
        author = db.StringProperty()
        email = db.EmailProperty()
    
    class MainPage(webapp2.RequestHandler):
      def get(self):
        en = Greeting(author='hellooo', email=db.Email("a@a.com"))
        en.put()
    
    app = webapp2.WSGIApplication([('/', MainPage)],
                                  debug=True)
    

    得到这样的值

    dev~devchat> x = Greeting.get_by_id(2)
    dev~devchat> x.author
    u'hellooo'
    dev~devchat> x.email
    u'a@a.com'
    dev~devchat> x.email.ToXml()
    u'<gd:email address="a@a.com" />'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-19
      • 2012-04-17
      • 1970-01-01
      • 2011-11-27
      相关资源
      最近更新 更多