Hi all

Martin Hsu suggested to make sure that this is included so I now have this in 
settings.py

TEMPLATE_CONTEXT_PROCESSORS=
("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n")

Still {{ perms }} is empty or at least not displayed.

Jeremy Dunck wrote:
> You must also render the template using RequestContext rather than
> Context in order for TEMPLATE_CONTEXT_PROCESSORS to be run.
> How is 'request' getting into your template context?
> Show us the view. :)

Here is the view:

def user(request):
     ''' Provides information on the currently logged in user. '''

     message = ''

     # This is an object that represents the currently logged-in user.
     # If the user isn't logged in, this will instead be an AnonymousUser object
     user = request.user

     # How to tell if a user is logged in.
     if request.user.is_authenticated():
         # Do something for authenticated users.
         debug = 'User is authenticated.'
     else:
         # Do something for anonymous users.
         debug = 'User is not authenticated.'
         return HttpResponseRedirect("/login/")

     # now user is authenticated, and has name == request.user.username

     message = '<br>This user '
     if user.has_perm('lab.add_test'):
         message = message + 'can add a lab test.<br>'
     else:
         message = message + 'cannot add any lab tests.<br>'

     if user.is_authenticated():
         permissions = user.get_all_permissions()
     else:
         permissions = ''

     data = {'request': request,
             'user': user,
             # passing through permissions is just for testing.
             # I should just use {{ perms }} in the template
             'permissions': permissions,
             'message': message,
             'debug': debug,
     }

     return render_to_response('lab/user.html', data)

------------------------------------------------------------
Here is part of the template user.html

<p>Permissions:<br>
{% for permission in permissions %}
&nbsp;&nbsp; + {{ permission }} <br>
{% endfor %}
</p>

perms={% if perms.lab %}
     yes perms
{% else %}
     no perms
{% endif %}

<p>{{ message }}</p>

-------------------------------------------------------------
And here is the output I get:

Permissions:
    + lab.change_test
    + lab.add_test
    + lab.add_experiment
    + lab.delete_experiment
    + lab.delete_test
    + lab.change_experiment
perms= no perms
This user can add a lab test.


I could create a dictionary in the view of all the permission things I'd need 
in a 
template and pass that in but the {{ perms }} seems like it is really what I 
should 
be using as it supposed to be automatically available from the request object.

-- 
Michael Lake




--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to