【问题标题】:How to retrieve data from a datastore in Python on Google App Engine via an HTTP response如何通过 HTTP 响应从 Google App Engine 上的 Python 数据存储中检索数据
【发布时间】:2011-04-25 01:32:48
【问题描述】:

我正在通过 httpRequest get 方法向 Google App Engine 发送数据。这一切顺利,并存储在数据存储中。但是如何通过 HTTP 从 Google App Engine 返回结果,或者有没有其他方法可以做到这一点?

任何帮助都会很有用。

【问题讨论】:

    标签: python google-app-engine http


    【解决方案1】:

    就个人而言,我更喜欢使用模型来定义我的数据

    from google.appengine.ext import db
    
    class SomeData(db.model):
        attr1 = db.StringProperty(required=Ture)
        attr2 = db.StringProperty()
        ..........
    

    然后,我可以检索数据

    data = SomeData.get_by_id(id)
    

    用于路由

    routes = [
        (r'/SomeData/(.*)', DataHandler)
    ]
    

    数据处理程序

    class DataHandler(BaseHandler):
        def get(self, id):
            data = SomeData.get_by_id(int(id))
            (render the data in the format you like here)
    

    现在,您可以通过以下 URL 按 id 访问您的数据:http://{your site}/SomeData/{id}

    【讨论】:

      【解决方案2】:
      class YourClass(webapp.RequestHandler):
        def get(self):
          self.response.out.write("Your Output")
      

      这是在 GAE 中为 get 方法写一些东西的基本模板。您是否按照有关创建留言簿应用程序的 App Engine 教程进行操作,如果没有,我认为这是一个很好的起点。

      【讨论】:

        猜你喜欢
        • 2014-04-20
        • 1970-01-01
        • 1970-01-01
        • 2011-11-11
        • 1970-01-01
        • 1970-01-01
        • 2011-05-26
        • 1970-01-01
        • 2012-02-19
        相关资源
        最近更新 更多