Login

Snippets by msanders

Snippet List

group_required decorator

This snippet provides a @group_required decorator. You can pass in multiple groups, for example: @group_required('admins','editors') def myview(request, id): ... Note: the decorator is based on the snippet [here](http://fragmentsofcode.wordpress.com/2008/12/08/django-group_required-decorator/) but extends it checking first that the user is logged in before testing for group membership - [user_passes_test](http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.user_passes_test) does not check for this by default. It is important to check that the user is first logged in, as anonymous users trigger an AttributeError when the groups filter is executed.

  • decorator
  • auth
  • groups
Read More

msanders has posted 1 snippet.