开发者

Any way to make dict passed to URL express in regexp in GAE?

Say, I have a dict

URLS = {'admin' : '/admin/(.*)'}

and if I do so

application = ([
(r(URLS['admin']), AdminPage)
], debug=True)

google app engine will raise an error

NameError: name 'r' is not defined

I really rea开发者_高级运维lly need to pass dictionary described in regexp to URL map for making my code more module.

What should I do to make it work?

thank you for your help!


The 'r' is a string prefix to escape some sequences for regular expression. It is not a function. http://docs.python.org/reference/lexical_analysis.html#string-literals

URLS = {'admin' : r'/admin/(.*)'}

application = webapp.WSGIApplication([
(URLS['admin'], AdminPage)
], debug=True)

The "webapp.WSGIApplication" will compile these strings to regex itself.


I believe re.compile is what you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜