每个请求调用Django自定义上下文处理器两次 [英] Django custom context processor being called twice per request

查看:130
本文介绍了每个请求调用Django自定义上下文处理器两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的自定义上下文处理器,每个请求只需要运行
一次。放入一些日志钩后,我发现
每个请求被调用两次。

I created a simple custom context processor that needs to only be run once per request. After putting in some logging hooks I found that it is being called twice per request.

这是一个在文档中错过的已知功能?
是否与继承树中的模板数有关?
这是1.03中的错误吗?

Is this a known "feature" that a missed in the docs? Is it related to the number of templates in the inheritance tree? Is it a bug in 1.03?

推荐答案

我想到了这个问题。如果返回除原始上下文之外的字典,则上下文处理器似乎被再次执行。不知道为什么,我不能确定,因为我没有看底层的代码,但后来我更新了原始的上下文,并返回问题消失了。谢谢。

I figured out the issue. If a dictionary other than the original context is returned then the context processor seems to be executed again. Not sure why, and I can't be sure because I didn't look at the underlying code, but the after I updated the original context and returned that the issue went away. Thanks.

这篇关于每个请求调用Django自定义上下文处理器两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆