简体   繁体   English

上下文处理器是访问 Django 中全局变量的唯一方法吗?

[英]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?我正在创建一个网站,我必须访问页脚部分的全局变量,我发现上下文处理器是访问全局变量的一种方法,我的问题是上下文处理器是访问 django 中全局变量的唯一方法吗?

Technically you can use middleware (see https://www.valentinog.com/blog/django-middleware/ ), but context processors are by far the better option.从技术上讲,您可以使用中间件(请参阅https://www.valentinog.com/blog/django-middleware/ ),但上下文处理器是更好的选择。

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.我想中间件的用例是如果您需要根据响应更改传递给上下文的参数,而不是上下文处理器允许您执行的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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