I need to render my site without navbar if there is an argument in the request like nv=false and I want to pass a variable to context based on this so that the main template shows the block or not. my site also has lots of json-rpc functions, and I don't want to add extra overhead on it. how can I do this without rewriting all my views? (they are not class based and my site uses django 1.8)
Just add context processor that will add this variable to context. Context processor is a simple python function
def navbar(request):
return {'navbar_enabled': request.GET.get('nv', False)
and add it to the list of template context processors
TEMPLATE_CONTEXT_PROCESSORS = (
...
'MODULE_NAME.navbar',
...
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With