0
我来到这里,因为我对Django和Thread有个疑问。我阅读文档http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#template-tag-thread-safety,我想现在如果下一个代码也可能在渲染上下文中受到影响。Django线程安全模板标签
class ChatterCountNode(NodeBase):
def __init__(self, channelname, varname):
self.channelname = channelname
self.varname = varname
def render(self, context):
channelname = self.getvalue(context, self.channelname)
varname = self.getvalue(context, self.varname)
count = get_channel_count(channelname)
context[varname] = count
return ''
嗯,谢谢。 想象我们在模板中有下一个代码,我们会产生不良效果吗?
{% get_chatters_count "zb_3" as zb3 %} {{zb3}}
{% get_chatters_count "zb" as zb %} {{zb}}
{% get_chatters_count "zb_1" as zb1 %} {{zb1}}
{% get_chatters_count "zb_2" as zb2 %} {{zb2}}
好的,只有我们希望在循环中使用templatetag来实例化并保存值时,问题才会出现。 – Acti67 2010-06-01 08:25:43