Python ValueError:基数为10的int()的文本无效

Python ValueError:基数为10的int()的文本无效,python,google-app-engine,Python,Google App Engine,我在尝试使用从单个条目到单个页面检索数据时收到以下错误,例如foobar.com/page/1将显示id 1中的所有数据: ValueError: invalid literal for int() with base 10 以下是文件: 视图.py class One(webapp.RequestHandler): def get(self, id): id = models.Page.get_by_id(int(str(self.reques

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

ValueError: invalid literal for int() with base 10
以下是文件:

视图.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))
url.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: '' 回溯(最近一次呼叫最后一次): 文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/ext/webapp/\uuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu__ handler.get(*组) get中第72行的文件“/Volumes/foobar/views.py” id=models.Page.get\u by\u id(int(str(self.request.get(“id”))) ValueError:基数为10的int()的文本无效:“”
self.request.get(“id”)
更改为简单的
id
,它已经被传递给
get
处理程序


正如您所拥有的,该代码只适用于像
/browse/1/?id=1

这样的URL,我不太确定您在这里想要实现什么。第一行:

    id         = models.Page.get_by_id(int(str(self.request.get("id")))) 
返回具有从查询字符串获取的ID的页面对象。要使其与传入的参数一起工作,请将其更改为:

    id         = models.Page.get_by_id(int(id)) 
Odder是第二行:

    page_query = models.Page.get(db.Key.from_path('Page', id))

这不会返回查询-它返回一个页面对象,如果将“id”替换为“int(id)”,则执行与第一行完全相同的操作。您想在这里实现什么?

我的一个代码中也有类似的错误。我只是做了一个简单的技巧,先把它转换成十进制,然后再把它转换成int
int(decimal(str(self.request.get(“id”)))
这个错误(我相信你知道——或者应该知道,你似乎在编程方面走得很远)意味着你正在键入/读取一个无效的文本(无效字符)对于以10为基数的值(即0-9个数字)。

感谢您的帮助,现在了解错误。BadArgumentError:参数2应为整数id或字符串名称;收到(一页)。我正试图将一个条目拉回到页面上。例如,localhost:8080/browse/1/-将显示条目1 localhost:8080/browse/2/-将显示条目2等。。list.html包含:{%for page%}{{page.title}}{%endfor%}