2014年5月16日 星期五

Python 列出所有組合


>>> list(itertools.combinations(range(1, 5), 2))
[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]

2014年5月14日 星期三

2014年5月12日 星期一

Flask get all routing rules

for rule in app.url_map.iter_rules():
    options = {}
    for arg in rule.arguments:
        options[arg] = "[{0}]".format(arg)

    methods = ','.join(rule.methods)
    url = url_for(rule.endpoint, **options) 
 
    print rule.endpoint
    print methods
    print url
 
 
 
 
References :
python - get a list of all routes defined in the app - Stack Overflow

flask url path param

request.path             /page.html
request.script_root      /myapplication
request.base_url         http://www.example.com/myapplication/page.html
request.url              http://www.example.com/myapplication/page.html?x=y
request.url_root         http://www.example.com/myapplication/
 
request.referrer
 
request.args             GET params
 
 
 
 
 
References :
python - Flask request fields to get url path - Stack Overflow