祖先查询解析错误 [英] Ancestor query parse error

查看:157
本文介绍了祖先查询解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的祖先查询起作用,但我不断收到此错误:
$ b

I am trying to get my ancestor query to work but I keep getting this error:


BadQueryError:解析错误:标识符是符号
的保留关键字ANCESTOR

BadQueryError: Parse Error: Identifier is a reserved keyword at symbol ANCESTOR

在这一行:

at this line:

TweepleKey(twitter_handle))

我正在关注使用Datastore 教程(可行),但是当我试图将祖先查询的概念应用于我的代码时(见下文),它会一直产生上述错误。

I was following Using the Datastore tutorial (which works) but when I tried to apply the concepts of ancestor query to my code (see below) it keeps producing the above mentioned error. Where did I go wrong?

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)


推荐答案

GQL reference 说要使用 WHERE ANCESTOR IS

这篇关于祖先查询解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆