我正在努力让我的祖先查询 https://developers.google.com/appengine/docs/python/datastore/structuring_for_strong_consistency工作,但我不断收到此错误:
BadQueryError:解析错误:标识符是符号处的保留关键字
祖先
在这一行:
TweepleKey(twitter_handle))
我正在关注使用数据存储 https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingdatastore教程(有效),但是当我尝试将祖先查询的概念应用于我的代码时(见下文),它不断产生上述错误。我哪里做错了?
import cgi
import urllib
import webapp2
import cgi
from google.appengine.ext import db
# defines a data model for a geotweet
# GeoTweet model has 1 property: twitter_handle
class GeoTweet(db.Model):
twitter_handle = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
def TweepleKey(twitter_handle=None):
# Constructs a Datastore key for a TweepleStore entity with twitter_handle
return db.Key.from_path('TweepleStore', twitter_handle or 'default_handle')
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write("""<html><body>""")
twitter_handle = self.request.get('twitter_handle')
tweeple = db.GqlQuery("SELECT * "
"FROM GeoTweet "
"WHERE ANCESTOR = :1 "
"ORDER BY date DESC LIMIT 10",
TweepleKey(twitter_handle))
for t in tweeple:
if t.twitter_handle:
self.out.write('<b>Found %s. Saved on %s.</b>' % (t.twitter_handle, t.date))
else:
self.out.write('<b>%s was not found!' % twitter_handle)
self.response.out.write("""<form action="/search" method="post">
<div><textarea name="twitter_handle" rows="1" cols="20">@example</textarea>
<div><input type="submit" value="Find"></div>
</form>
</body>
</html>""")
class TweepleStore(webapp2.RequestHandler):
def post(self):
twitter_name = self.request.get('twitter_handle')
geotweet = GeoTweet(parent=TweepleKey(twitter_name))
geotweet.twitter_handle = twitter_name
geotweet.put()
self.redirect('/?' + urllib.urlencode({'twitter_name': twitter_name}))
app = webapp2.WSGIApplication([('/', MainPage),
('/search', TweepleStore)], debug=True)
The GQL 参考 https://developers.google.com/appengine/docs/python/datastore/gqlreference说要使用WHERE ANCESTOR IS
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)