Jeremy Logan Jeremy Logan - 3 months ago 26
Python Question

Retrieving werkzeug route variable args inside a before_request?

If you have variable arguments in your routes, like the "bar" here:

def foo(self, bar):
return bar

How can you retrieve that in a before_request, like here:

def before_request():


You can use request.view_args to get the path variables.

Also, you can replace @app.before_request with @app.url_value_preprocessor, like:

def br(endpoint, values):
    print request.path
    print values

Hence, you can get path variables from values and get url path from request.path.