RajeshD wrote:
> Firstly, the statement "user = User.objects.get(id=request.user.id)" is
> redundant -- you could directly use request.user instead of that query
> with the same effect.
> 
> As far as the actual problem is concerned, your Queryset is returning
> multiple rows because request.user.id probably resolves to None (in
> that case the query will match all User records). This in turn implies
> that request.user is not good.
> 
> Have a look at:
> http://www.djangoproject.com/documentation/authentication/#authentication-in-web-requests
> 
> That will tell you what you need to setup in your project in order for
> Django to populate request.user for you.
> 
> Beware also that request.user may not always point to a logged in user.
> Always check this with the is_anonymous() call or other permission
> method calls before you use the user instance for anything serious.
> 
> Good luck!
> -Rajesh
> 
> 
> > 
> 
Thanks again, Rajesh. That worked. Below is my rudimentary userinfo tag:


from django.template import Library, Node
from django.contrib.auth.models import User

register = Library()

def user_info(context):
     """
     Get user information
     """
     request = context['request']
     if request.user.is_authenticated():
         # Do something for authenticated users.
         user = request.user
     else:
     # Do something for anonymous users.
         user = None

     return {'current_user': user,}

register.inclusion_tag('user_info.html', takes_context=True)(user_info)



I guess one thing to remember is to always use RequestContext


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to