Google App Engine WSGIApplication中的hexdigest正则匹配
application = webapp.WSGIApplication(
[(r'/main/profile/([a-f0-9]{40})', ProfileHandler)],
debug=True)
上面参数中的正则表达式在Google App Engine中无法识别40个十六进制字符长的哈希值。
我得到的是404错误,而不是将匹配的40个十六进制字符长的个人资料ID传递给ProfileHandler。我的app.yaml文件将所有/main/.*的请求都转发到正确的Python脚本,所以这不是问题所在。这个正则看起来没问题,并且与GAE文档中的示例正则表达式相似。那么这个正则表达式到底哪里出错了呢?
2 个回答
0
我对Google App Engine没有经验,但我想问:
- 如果把
([a-f0-9]{40})
改成([a-fA-F0-9]{40})
会发生什么? - 你确定使用的是组
$1
,而不是整个匹配的内容(包括/main/profile/
)吗?
2
我无法重现你遇到的问题。这里有一段我自己的代码:
index.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))
app.yaml
application: someapp
version: 1
runtime: python
api_version: 1
handlers:
- url: /main/.*
script: index.py
应用程序正在监听8082端口
GET: http://localhost:8082/main/profile/4c4f630aef49c0065c22eb3dd35a00f5787f4816
RESPONSE: PROFILE IS:4c4f630aef49c0065c22eb3dd35a00f5787f4816