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?

@register.tag(name='sometag')
def sometag(parser, token):
try:
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):
try:
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,
Thomas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment