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

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -