Monday, May 30, 2011

How to get user object from RequestContext?

How do I get the user related to the current request in templatetag?
Using RequestContext?

def sometag(parser, token):
tagname, model_inst = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires exactly
one argument" % tagname

return FormatNode(model_inst)

class FormatNode(template.Node):

def __init__(self, model_inst):
self.model_inst = template.Variable(model_inst)

def render(self, context):
p = self.model_inst.resolve(context)
# Here I'd like to get hold of the user object, but how??
except Exception, e:
return ''

Thanks in advance,

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment