Sunday, July 29, 2012

Re: Is there a way to use 'request.user' in a custom template tag without an inclusion tag?

class EditableNode(template.Node):
def __init__(self, location_name):
self.location_name = location_name.encode('utf-8').strip("'")
def render(self, context):
obj = Placeholder.objects.filter(location=self.location_name)
if request.user.is_authenticated():
for x in obj:
return "%s<br/><a href='/admin-edit/%s'>edit</a>" % (x, self.location_name)
else:
for x in obj:
return x



that `request` variable isn't declared anywhere, that's what that "global name `<varname>` does not exist" error mean.

I *think* you've got to use context['user'], try that. Else, try context['request'].user

--
"The whole of Japan is pure invention. There is no such country, there are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny 
(")_(") to help him gain world domination.

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