开发者

How to retrieve data from a datastore in Python on Google App Engine via an HTTP response

开发者 https://www.devze.com 2023-02-28 17:11 出处:网络
I am sending data to the Google App Engine via the httpRequest get method. This goes perfectly well and gets stored in开发者_如何学Python the datastore. But how to return the result from the Google Ap

I am sending data to the Google App Engine via the httpRequest get method. This goes perfectly well and gets stored in开发者_如何学Python the datastore. But how to return the result from the Google App Engine via HTTP or is there any other method for doing the same?

Any help will be useful.


Personally, I prefer to using the model to define my Data

from google.appengine.ext import db

class SomeData(db.model):
    attr1 = db.StringProperty(required=Ture)
    attr2 = db.StringProperty()
    ..........

Then, I could retrieve the data with

data = SomeData.get_by_id(id)

For the routing

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

Data Handler

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

Now, you could access your data by id through the URL: http://{your site}/SomeData/{id}


class YourClass(webapp.RequestHandler):
  def get(self):
    self.response.out.write("Your Output")

That is the basic template to write something out of for get method in GAE. Did you follow the App Engine tutorial on creating a guestbook application, if not, I think that is a good place to start.

0

精彩评论

暂无评论...
验证码 换一张
取 消