How To Restrict My Students To Don't Access Teacher Area In Django?
I'm creating a website where there is two types of users, Students and Teachers. I had created one register and login page for authentication. Now by default all the users who sig
Solution 1:
You can create your own view decorator that checks that a user is a member of a group
from django.contrib.auth.decorators import user_passes_test
defis_teacher(user):
return user.groups.filter(name='Teacher').exists()
@user_passes_test(is_teacher)defmy_view(request)
...
Then all you have to do is create a Group with name "Teacher" and add teachers to that group
Solution 2:
Try using the is_staff field from built-in User model. For teachers, set it to true and for children set it to false. On the basis of it decide the rights given to each. Hope it helps.
Post a Comment for "How To Restrict My Students To Don't Access Teacher Area In Django?"