【发布时间】:2015-06-26 06:07:13
【问题描述】:
我遇到了谷歌应用引擎的问题。我正在尝试实现一个 Person ndb 模型,它将存储一个人的基本信息。但是,当我尝试在数据库中查询某个键时,我在回溯中不断收到 Nonetype 错误:
File "xxxx", line 104, in get
parent = ndb.Key('Person', users.get_current_user().email())
AttributeError: 'NoneType' object has no attribute 'email'
这是与错误相关的代码:
这是我声明模型的地方
class Person(ndb.Model):
dev_id = ndb.StringProperty()
num_readings = ndb.IntegerProperty()
这里我只是想稍后在同一个文件中使用它:
class MainPageLI(webapp2.RequestHandler):
# Front page for those logged in
def get(self):
user = users.get_current_user()
parent = ndb.Key('Person', users.get_current_user().email())
person = parent.get()
if person == None:
person = Person(id=users.get_current_user().email())
person.temperature_unit = 'celsius'
person.time_zone = 8.00
"""person.notify_type = ['by-time']
person.notify_time_value = 4
person.notify_time_unit = 'days'
person.notify_parameters = ['by-temp']
person.notify_temperature_abe = 'exactly'
person.notify_temperature_value = 20
person.notify_temperature_unit = 'celsius'
person.notify_light_abe = 'above'
person.notify_light_value = 90
person.notify_motion = 'present'"""
person.num_readings = 5
#person.history_log_value = 2
#person.history_log_unit = 'days'
person.put()
if user: # signed in already
params = urllib.urlencode({'username':users.get_current_user().nickname()})
template_values = {
'user_mail': users.get_current_user().email(),
'logout': users.create_logout_url(self.request.host_url),
'nickname': users.get_current_user().nickname(),
}
template = jinja_environment.get_template('frontuser.html')
self.response.out.write(template.render(template_values))
else:
self.redirect(self.request.host_url)
注意:文件中的所有缩进都是正确的,它只是笨拙地复制粘贴(尤其是 MainPageLI 段,前几行在文件中被制表符)。
任何和所有的帮助将不胜感激!谢谢:)
【问题讨论】:
标签: python google-app-engine google-cloud-datastore app-engine-ndb