我有一个使用Google App Engine Launcher在本地正常运行的ndb查询,但是当我将应用程序部署到GAE时,查询无法在数据库中找到任何匹配项(我在数据库中以相同的方式在两个环境中创建了条目)
查询是:
user = users.get_current_user()
_website_sect_name = 'TVplus_Access'
account_chk = Account.chk_account(user.email(), _website_sect_name)
ndb模型和功能是:
DEFAULT_WEBSITE_NAME = 'TVplus_Access'
def access_lvl_key(website_sect_name=DEFAULT_WEBSITE_NAME):
"""Constructs a Datastore key for a Access_lvl entity with website_sect_name."""
return ndb.Key('Access_lvl', website_sect_name)
class Account(ndb.Model):
"""Models an individual Access_lvl entry."""
email = ndb.StringProperty(required=True)
nickname = ndb.StringProperty(indexed=True)
date = ndb.DateTimeProperty(auto_now_add=True)
author = ndb.UserProperty()
@classmethod
def chk_account(self, _email, _website_sect_name):
no_acct = 0
try:
website_key = ndb.Key('Access_lvl', _website_sect_name)
account_email = Account.query(Account.email == _email, ancestor=website_key).order(-Account.date).get().to_dict()
return account_email
except:
return no_acct
添加用户的功能是:
class Adduser(webapp2.RequestHandler):
def post(self):
website_sect_name = self.request.get('website_sect_name',
DEFAULT_WEBSITE_NAME)
account = Account(parent=access_lvl_key(website_sect_name))
if users.get_current_user():
account.author = users.get_current_user()
account.email = self.request.get('email')
account.put()
account.nickname = self.request.get('nickname')
account.put()
query_params = {'website_sect_name': website_sect_name}
self.redirect('/useradmin?' + urllib.urlencode(query_params))
在我的本地计算机上,Account.chk_account()的返回响应为:
{' date&#39 ;: datetime.datetime(2014,7,2,22,6,22,854000),'昵称':你' Roger', '电子邮件':你' roger@test.com','作者&#39 ;: users.User(email =' admin@test.com', _USER_ID =' 123300217217163669814')}
但是在部署服务器上,该函数返回来自" no_acct"的除外代码。 0,告诉我chk_account()由于某种原因出现空(电子邮件帐户roger@test.com已添加到两个环境中的TVplus_Access)
答案 0 :(得分:0)
据我所知,GAE远程控制面板有一些检查数据库结构和条目的工具。你可以访问它,看看你添加的帐户是否真的存在吗?
答案 1 :(得分:0)
问题出在chk_account = definition中。已删除'。订单(-Account.date)'来自Account.query()。更正了代码部分:
@classmethod
def chk_account(self, _email, _website_sect_name):
no_acct = 0
try:
website_key = ndb.Key('Access_lvl', _website_sect_name)
account_email = Account.query(Account.email == _email, ancestor=website_key).get().to_dict()
return account_email
except:
return no_acct