Skip to content

Instantly share code, notes, and snippets.

@ityoung
Last active March 19, 2019 03:39
Show Gist options
  • Save ityoung/5c05dd0389fcab3fd8089f750b593d1d to your computer and use it in GitHub Desktop.
Save ityoung/5c05dd0389fcab3fd8089f750b593d1d to your computer and use it in GitHub Desktop.
Dynamically create routes with flask. 动态生成flask路由. Mock server可能会用到
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