python - Centralizing Flask routes -
my colleague place routes web server in single routing file instead of spreading them around on bunch of functions. how in java/play:
get /recovery controllers.application.recovery() /signup controllers.application.signup(lang="sv") /<:lang>/signup controllers.application.signup(lang: string)
is feasible/easy in flask?
yes, easy:
from flask import flask import controllers.application app = flask(__name__) routes = '''\ /recovery controllers.application.recovery /signup controllers.application.signup /<lang>/signup controllers.application.signup''' route in routes.splitlines(): method,path,func = route.split() app.add_url_rule(rule=path, view_func=eval(func), methods=[method]) app.run()
Comments
Post a Comment