开发者

having 2 groups of users to view 2 different views in django

i have a django project that has 2 types of users ( teachers and students in my case )

i want each group of them to view a different page when they login. how is that possible ?

开发者_开发知识库

or how to know what group a certain user belong to ?

thanks in advance


To get the groups of a user check the docs on authentication.

User objects have two many-to-many fields: models.User. groups and user_permissions. User objects can access their related objects in the same way as any other Django model:

myuser.groups = [group_list]

So if you want to check if a user is member of the group teachers:

if myuser.groups.filter(name='teachers'):
    print "myuser is a teacher"
    ...

Considering the redirection see this answer: Django - after login, redirect user to his custom page --> mysite.com/username

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜