python - Flask: URLs w/ Variable parameters -


i have url string want build in following manner:

http://something.com/mainsite/key1/key2/key3/keyn

how generate in url mapping n variable number?

how keys?

thanks

there 2 ways this:

  1. simply use path route converter:

    @app.route("/mainsite/<path:varargs>") def api(varargs=none):     # mainsite/key1/key2/key3/keyn     # `varargs` string contain above     varargs = varargs.split("/")     # , list of strings 
  2. register own custom route converter (see werkzeug's documentation full details):

    from werkzeug.routing import baseconverter, validationerror  class pathvarargsconverter(baseconverter):     """convert remaining path segments list"""      def __init__(self, url_map):         super(pathvarargsconverter, self).__init__(url_map)         self.regex = "(?:.*)"      def to_python(self, value):         return value.split(u"/")      def to_url(self, value):         return u"/".join(value)  app.url_map.converters['varargs'] = pathvarargsconverter 

    which can use this:

    @app.route("/mainsite/<varargs:args>") def api(args):     # args here list of path segments 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -