I was trying to get a Model object from datastore using the key passed from query string. It worked before that, however, recently, when I named the file from restaurantProfile.html to restaurant_profile.html. I don't know from which part went wrong caused the problem.
我试图使用查询字符串传递的键从datastore获取模型对象。然而,在此之前,我从餐馆的档案中命名了这个文件。restaurant_profile.html html。我不知道是哪里出了问题造成了这个问题。
My restaurant key should contains the key. However, from the GAE log, I've set custom debug to see what contains in Restaurant key passed to my handler (Result):
我的餐厅钥匙应该有钥匙。但是,从GAE日志中,我设置了自定义调试,以查看传递给我的处理程序(结果)的Restaurant key中的内容:
GAE Log:
Restaurant Key = <bound method Restaurant.key of <persistence.model.Restaurant object at 0x5cd3c5acd5768900>>
Can anyone tell me what's got wrong here? The restaurant key doesn't seem to be passed to the handler.
谁能告诉我这里出了什么问题吗?餐厅的钥匙似乎没有传递给管理员。
<a href="/restaurant_profile?restaurant_key={{ key }}">
Handler Class:
处理程序类:
class RestaurantProfileHandler(webapp.RequestHandler):
def get(self):
restaurant_key = self.request.GET.get(u'restaurant_key')
logging.debug('Restaurant Key = %s', restaurant_key)
Error: "invalid literal for int() with base 10" for following:
错误:“以10为基数的int()无效文字”
def get_RestaurantDetails(restaurant_key):
if restaurant_key:
restaurant = db.Key.from_path('Restaurant', int(restaurant_key))
return db.get(restaurant)
Code to retrieve the key:
检索密钥的代码:
for restaurant in foundRestaurants:
result_data[restaurant.key] = restaurant
Problem solved by following:
问题解决:
key = restaurant.key().__str__()
result_data[key] = restaurant
2 个解决方案
#1
1
Problem solved by following:
问题解决:
key = restaurant.key().__str__()
result_data[key] = restaurant
#2
0
Can anyone tell me what's got wrong here?
谁能告诉我这里出了什么问题吗?
it's exactly like it says: restaurant_key
is a method. You can't call int()
upon that; did you mean to call int()
upon the result of calling restaurant_key()
?
就像它说的:restaurant_key是一个方法。不能调用int();您的意思是在调用restaurant_key()的结果之后调用int()吗?
As for why restaurant_key
is a method, well, that's what self.request.GET.get(u'restaurant_key')
returned. Maybe you should re-read the documentation...
至于为什么餐馆钥匙是一种方法,嗯,这就是self。request。get.get (u'restaurant_key')返回的原因。也许你应该重读一下文档……
#1
1
Problem solved by following:
问题解决:
key = restaurant.key().__str__()
result_data[key] = restaurant
#2
0
Can anyone tell me what's got wrong here?
谁能告诉我这里出了什么问题吗?
it's exactly like it says: restaurant_key
is a method. You can't call int()
upon that; did you mean to call int()
upon the result of calling restaurant_key()
?
就像它说的:restaurant_key是一个方法。不能调用int();您的意思是在调用restaurant_key()的结果之后调用int()吗?
As for why restaurant_key
is a method, well, that's what self.request.GET.get(u'restaurant_key')
returned. Maybe you should re-read the documentation...
至于为什么餐馆钥匙是一种方法,嗯,这就是self。request。get.get (u'restaurant_key')返回的原因。也许你应该重读一下文档……