I have a setup looking something like this:
def foo_decorator(function):
@wraps(function)
def decorator(*args, **kwargs):
print kwargs
return function(*args, **kwargs)
return decorator
@foo_decorator
def analytics(request, page_id, promotion_id):
pass
Outputting:
{'promotion_id': u'11','page_id': u'119766481432558'}
Why is my decorator not getting request passed to it?
requestisn’t a keyword argument to the view, it’s the first positional argument. You can access it asargs[0].I would recommend that you change the function signature to include
requestexplicitly: