开发者

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

开发者 https://www.devze.com 2023-03-20 11:38 出处:网络
Say, I have a dict URLS = {\'admin\' : \'/admin/(.*)\'} and if I do so application = ([ (r(URLS[\'admin\']), AdminPage)

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

精彩评论

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