gpt4 book ai didi

python - WSGIApplication 处理程序的默认值?

转载 作者:太空宇宙 更新时间:2023-11-04 06:26:13 24 4
gpt4 key购买 nike

我有以下代码:

class MyHandler(webapp.RequestHandler):
def get(self, page_text, page=1): # page default value is 1, but it doesn't work

application = webapp.WSGIApplication([('/something/(page(\d+))?/?', MyHandler)], debug=True)

它应该捕获如下 URL:

/something/
/something/page1
/something/page1/
/something/page2
/something/page2/
/something/pageN
/something/pageN/

当使用第一个 URL (/something/) 时,我仍然期望 page 等于 1,但实际上 page 等于无。为什么会这样?

最佳答案

只是等待一些正则表达式专家回答的解决方法:

class MyHandler(webapp.RequestHandler):
def get(self, page_text = None, page = 1)

application = webapp.WSGIApplication([('/something/', MyHandler)
('/something/(page(\d+))?/?',MyHandler)],
debug=True)

关于python - WSGIApplication 处理程序的默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7864718/

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