Last active
March 19, 2019 03:39
-
-
Save ityoung/5c05dd0389fcab3fd8089f750b593d1d to your computer and use it in GitHub Desktop.
Dynamically create routes with flask. 动态生成flask路由. Mock server可能会用到
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in ['aa', 'bb']: | |
option = {} | |
option['endpoint'] = i | |
rule = app.url_rule_class('/' + i, methods=('GET',), **option) | |
app.url_map.add(rule) | |
app.view_functions[i] = lambda: jsonify({'success': i}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment