Jeremy Logan Jeremy Logan - 1 year ago 145
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():

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download