allow certain users to access certain views

36 views
Skip to first unread message

sum abiut

unread,
Feb 19, 2015, 12:50:14 AM2/19/15
to django...@googlegroups.com
Hi,
I have an app that i am trying to allow only certain users to access specific views. For example all users can view the home page but for a certain link. i only want to allow the HR manager to access it.

Could you please point me to right direction.

Cheers


James Schneider

unread,
Feb 19, 2015, 2:19:04 AM2/19/15
to django...@googlegroups.com

You should be able to handle this pretty easily with Django's built-in permission system.

Just create a group, add the users to it, and assign the requisite permissions to the group. Our add the needed permissions individually to each user.

https://docs.djangoproject.com/en/1.7/topics/auth/default/#permissions-and-authorization

Then all you'll need to do is wrap your views with the correct permission checks, or do the checks within the templates if you need to, like {% if 'foo.view' in perms %} assuming that you have the default context processors in place, or have included the contrib.auth processor.

You shouldn't need to do any permission checks for pages that are available to everyone.

Alternatively, you can tweak the user.is_staff attribute to True for those that need extra access, and use that as your permission check if you don't need anything fancy.

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y5VBRtsb2oFN5ZEPL2_57y%2BAhKqV-OnEqne2YAcACNxsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

sum abiut

unread,
Feb 19, 2015, 7:44:48 PM2/19/15
to django...@googlegroups.com
Hi James,

Thanks heaps for direction.

Cheers


For more options, visit https://groups.google.com/d/optout.



-
Reply all
Reply to author
Forward
0 new messages