Skip to main content
 首页 » 编程设计

python之错误为 "invalid literal for int() with base 10"的查询字符串

2025年05月04日21Terrylee

我试图使用从查询字符串传递的键从数据存储中获取模型对象。但是,最近,当我将文件从 restaurantProfile.html 命名为 restaurant_profile.html 时,它就起作用了。我不知道是哪个部分出了问题导致了这个问题。

我的餐厅 key 应该包含 key 。但是,从 GAE 日志中,我设置了自定义调试以查看传递给我的处理程序(结果)的餐厅 key 中包含的内容:

GAE Log: 
Restaurant Key = <bound method Restaurant.key of <persistence.model.Restaurant object at 0x5cd3c5acd5768900>> 

谁能告诉我这里出了什么问题?餐厅 key 似乎没有传递给处理程序。

<a href="/restaurant_profile?restaurant_key={{ key }}"> 

处理程序类:

class RestaurantProfileHandler(webapp.RequestHandler): 
def get(self): 
    restaurant_key = self.request.GET.get(u'restaurant_key') 
 
    logging.debug('Restaurant Key = %s', restaurant_key) 

以下错误:“以 10 为底的 int() 的无效文字”:

def get_RestaurantDetails(restaurant_key): 
   if restaurant_key: 
       restaurant = db.Key.from_path('Restaurant', int(restaurant_key)) 
       return db.get(restaurant) 

获取 key 的代码:

for restaurant in foundRestaurants: 
            result_data[restaurant.key] = restaurant 

问题解决如下:

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

请您参考如下方法:

问题解决如下:

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