简体   繁体   中英

Is context processor only way to access global variable in Django?

I am creating a website and i have to access golbal variables for the footer section and i found the context processor one way to access global variable and my question is that Is context processors one and only way to access global variable in django?

Technically you can use middleware (see https://www.valentinog.com/blog/django-middleware/ ), but context processors are by far the better option.

I guess the use case for middleware would be if you need to change what parameters your passing to the context based off of the response , rather than the request like a context processor allows you to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM