If I set a variable in my middleware, how do I make it available for my views in my view.py?

This is my middleware:

class Go():
    def process_view(self, request, view_func, view_args, view_kwargs):
        aaa = "hello"
        return None

If I go to my view.py and print aaa, I get an error.

+1
source share
2 answers

If you want it to be available in your views, you can add whatever you want to the object request, as it is ultimately passed on to your views.

request.myvar = 'hello'
+1
source

Try

request.aaa = "hello"

and then, in your opinion:

print request.aaa
+1
source

All Articles