python django 权限认证相关

  • 权限
CLICK ME

Group功能

    # 测试auth模块的Group功能
    from django.contrib.auth.models import Group
    Group.objects.get_or_create(name='user_group')
    user_group = Group.objects.get(name='user_group')
    # assign_perm('view_project', user_group) #需要加上app
    assign_perm('app.view_project', user_group)
    user = authenticate(username='test', password='test')
    user.groups.add(user_group)

    # 查看get_objects_for_user方法
    from guardian.shortcuts import get_objects_for_user
    user = authenticate(username='test', password='test')
    ret1 = get_objects_for_user(user,'app.view_project')
    ret3 = get_objects_for_user(user,'app.view_project').first()
    # print(ret2)
    # print(ret3)


  • 重写User模型和登录验证
CLICK ME

文章写的很好
https://www.cnblogs.com/chadiandianwenrou/p/7516224.html



  • things
CLICK ME

title



posted @ 2020-07-20 16:57  该显示昵称已被使用了  阅读(119)  评论(0编辑  收藏  举报