gpt4 book ai didi

python - 值错误 : invalid literal for int() with base 10 trying to retrieve a query parameter from Google App engine

转载 作者:行者123 更新时间:2023-11-28 16:54:55 26 4
gpt4 key购买 nike

我在尝试使用 Google App Engine 检索数据时收到以下错误从单个条目到单个页面,例如foob​​ar.com/page/1 将显示来自 id 1 的所有数据:

ValueError: invalid literal for int() with base 10

文件如下:

Views.py

class One(webapp.RequestHandler):    
def get(self, id):
id = models.Page.get_by_id(int(str(self.request.get("id"))))
page_query = models.Page.get(db.Key.from_path('Page', id))
pages = page_query

template_values = {
'pages': pages,
}

path = os.path.join(os.path.dirname(__file__), 'template/list.html')
self.response.out.write(template.render(path, template_values))

网址.py:

(r'/browse/(\d+)/', One),

错误:

Traceback (most recent call last):  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 501, in __call__    handler.get(*groups)  File "/Volumes/foobar/views.py", line 72, in get    id = models.Page.get_by_id(int(str(self.request.get("id"))))ValueError: invalid literal for int() with base 10: ''

最佳答案

self.request.get("id") 更改为简单的 id,它已经被传递给您的 get 处理程序。

您拥有的代码仅适用于 /browse/1/?id=1

这样的 URL

关于python - 值错误 : invalid literal for int() with base 10 trying to retrieve a query parameter from Google App engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1241395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com