google app engine webapp WSGIApplication中hexdigest的Regex匹配

2024-05-14 00:30:50 发布

您现在位置:Python中文网/ 问答频道 /正文

application = webapp.WSGIApplication(
    [(r'/main/profile/([a-f0-9]{40})', ProfileHandler)],
    debug=True)

上述参数中的regex将无法识别googleappengine中40个十六进制长的hexdigest。在

我得到404而不是ProfileHandler被传递匹配的40个十六进制长的profile ID应用程序yaml将所有/main/*传递到正确的python脚本,这样就不会出现问题。正则表达式看起来正常,resembles the example regex in GAE docs。这个正则表达式有什么问题?在


Tags: debugidtrue应用程序参数applicationmainprofile
2条回答

我没有使用谷歌应用程序引擎的经验,但是:

  • 如果将([a-f0-9]{40})更改为([a-fA-F0-9]{40}),会发生什么情况
  • 您确定使用了组$1,而不是整个匹配项(包括/main/profile/)?在

我不能重现你的问题。我有一个确切的代码:

在索引.py在

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class ProfileHandler(webapp.RequestHandler): 
    def get(self, *ar, **kw):
        self.response.out.write("PROFILE IS:" + ar[0])

run_wsgi_app(webapp.WSGIApplication(
[(r'/main/profile/([a-f0-9]{40})', ProfileHandler),],
                                 debug=True))

在应用程序yaml在

^{pr2}$

应用程序正在侦听端口8082

GET: http://localhost:8082/main/profile/4c4f630aef49c0065c22eb3dd35a00f5787f4816
RESPONSE: PROFILE IS:4c4f630aef49c0065c22eb3dd35a00f5787f4816

相关问题 更多 >