使用Dajngo通过代码添加xadmin用户和权限的方法-创新互联
创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

小编给大家分享一下使用Dajngo通过代码添加xadmin用户和权限的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
在开发的时候,用户要求在认证的时候自动添加xadmin登录账户和分配组权限
from django.contrib.auth.models import Group,User
from django.http import JsonResponse
def test(req):
name=req.POST['name']
account=req.POST['account']
password=req.POST['password']
an=Group.objects.filter(id=1).first() #二级管理组 是管理员在xadmin后台添加的权限组
user = User(username=account)
user.set_password(password)
user.is_superuser = False
user.is_active = True
user.first_name = name
user.is_staff = True
user.save() #先生成用户
user.groups.add(an)
return JsonResponse({'ret':0,'msg':'success'}) 当前文章:使用Dajngo通过代码添加xadmin用户和权限的方法-创新互联
分享地址:http://www.jxjierui.cn/article/iiogh.html


咨询
建站咨询
