[Django]-How to pass a value to every view with django middleware

7👍

Bars on your comment, you probably want to use a context processor to get your variable into the template context.

Edit for example

It’s pretty trivial, but here you go:

def my_context_processor(request):
    if request.session['my_variable']:
        return {'foo': 'bar'}

then you add myapp.mymodule.my_context_processor to TEMPLATE_CONTEXT_PROCESSORS in settings.py, and make sure you use the render shortcut in the view to render your template.

Leave a comment