Posted almost 7 years ago. Visible to the public. Linked content.

Python + Tornado - Variable length URL Parameters

If you want to catch variable length url parameters with tornado, first, you have to setup the correct regex routes:

Copy
(r"/some_method/?(?P<param_name>[A-Za-z0-9-]+)?/", FunctionHandler)

Don't forget to enclose the param groups (?P ... ) between question marks ?(?P ... )? to mark them as non-mendatory.

The function handler is like:

Copy
class FunctionHandler(tornado.web.RequestHandler): def get(self, **params): self.render("some_template_file.html", params = params, )

You'll be able to use the parameters variable in your template as follow:

Copy
params["param_name"]

Owner of this card:

Avatar
ThEo.GFX
Last edit:
almost 7 years ago
Posted by ThEo.GFX to ThEo.GFX's Cards
This website uses cookies to improve usability and analyze traffic.
Accept or learn more