在开发的时候,用户要求在认证的时候自动添加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'})
热门工具 换一换