How to delete user in django?

孤者浪人 提交于 2019-12-09 04:25:27
doniyor

You should change your code to:

@staff_member_required 
def del_user(request, username):    
    try:
        u = User.objects.get(username = username)
        u.delete()
        messages.success(request, "The user is deleted")            

    except User.DoesNotExist:
        messages.error(request, "User doesnot exist")    
        return render(request, 'front.html')

    except Exception as e: 
        return render(request, 'front.html',{'err':e.message})

    return render(request, 'front.html') 

and display the err in your template to see further error messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!