Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django variable available to all the views

With context_processors it' s easy to define a callable which results variables available to all the templates. Is there any similar technique which makes a variable available to all the views? Is that somehow possible? Maybe with some workaround?

Django: 2.2 Python: 3.5.3

.

like image 793
user2194805 Avatar asked Sep 01 '25 04:09

user2194805


1 Answers

You may want to implement a custom Middleware.

https://docs.djangoproject.com/en/dev/topics/http/middleware/

This lets you execute custom code for every request and attach the results to the request object, which is then accessible in your view.

like image 120
AbrahamCoding Avatar answered Sep 02 '25 16:09

AbrahamCoding