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