Skip to content Skip to sidebar Skip to footer

If I Set A Variable In My Middleware, How Do I Make That Available To My Views In My Views.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 into my views.py and p

Solution 1:

If you want it available in your views, you can add anything you want to the request object as that's ultimately passed down to your views.

request.myvar = 'hello'

Solution 2:

Try

request.aaa = "hello"

and then in your view:

print request.aaa

Post a Comment for "If I Set A Variable In My Middleware, How Do I Make That Available To My Views In My Views.py?"