[Answered ]-Pass a value from a decorator to a context processor in django

2👍

You can have the decorator add a property to the request object, and then access that value in the context processor.

For example, you can use the following decorator:

def add_value(function):
    def wrap(request, *args, **kwargs):
        request.extra_value = True
        return function(request, *args, **kwargs)
    return wrap

Then you can access it in the context processor:

def extra_value_context_processor(request):
    if request.extra_value:
        ...

Leave a comment