开发者

Wrapping a non-generic Django view

开发者 https://www.devze.com 2022-12-22 22:11 出处:网络
I want to inject one additional variable into the context of a view that belongs to a 3rd-party application without editing the code of that application. Is there a way to do this by wrapping the (non

I want to inject one additional variable into the context of a view that belongs to a 3rd-party application without editing the code of that application. Is there a way to do this by wrapping the (non-generic) view? It doesn't accept an extra_context parameter, so the approach described in this SO thread won't work. I know I could create a context processor, but that seems like a lot of开发者_JAVA技巧 overhead, having this variable available on every page when I just want it in one view. Or is there a way to narrow the scope of a context processor?


I think a context processor is the way to go, but with a splash of logic in there that checks the request path (for instance) and only bothers digging out and setting the variable for the occasions when it's needed

0

精彩评论

暂无评论...
验证码 换一张
取 消