On Monday, 30 May 2011 18:07:16 UTC+1, MrMuffin wrote:
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" % tagnamereturn 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
Assuming the template was rendered with RequestContext as you imply, you can do `context['user']`.
--
DR.
-- 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