开发者

Query String with error "invalid literal for int() with base 10"

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.

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 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:

def get_RestaurantDetails(restaur开发者_StackOverflowant_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


Problem solved by following:

 key = restaurant.key().__str__()
            result_data[key] = restaurant


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()?

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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜