is there a simple way to get group names of a user in django

前端 未结 4 577
独厮守ぢ
独厮守ぢ 2021-01-30 12:41

I tried following Code with the help of the django.contrib.auth.User and django.contrib.auth.Group

for g in request.user.groups         


        
4条回答
  •  盖世英雄少女心
    2021-01-30 13:23

    This is better

    if user.groups.filter(name='groupname').exists():
        # Action if existing
    
    else:
        # Action if not existing
    

提交回复
热议问题