views:

39

answers:

1

Hi,

I am coming here, because I have a question about Django and Thread. I read the documentation http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#template-tag-thread-safety and I would like to now if the next code could be impacted also, at the rendering context.

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 ''

Thank you for your time.

Stéphane

A: 

No, your code is thread safe. See the example they have in the docs with the cycle tag.

Vasil
Hmmm, thank you.Imaginate that we have the next code in a template, can we have undesirable effects? <div> <p>{% get_chatters_count "zb_3" as zb3 %} {{zb3}}</p> <p>{% get_chatters_count "zb" as zb %} {{zb}}</p> <p>{% get_chatters_count "zb_1" as zb1 %} {{zb1}}</p> <p>{% get_chatters_count "zb_2" as zb2 %} {{zb2}}</p> </div>Thank you.
Acti67
Ok, the problem come only if we want to use a templatetag in a loop for exemple and save a value in the instance.
Acti67