Python Django 获取所有用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23139657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django Get All Users
提问by Adam
I am just starting out with Django and I am messing around just trying to pull a full list of users from postgres.
我刚刚开始使用 Django,我只是想从 postgres 中提取完整的用户列表。
I used the following code:
我使用了以下代码:
group = Group.objects.get(name="Admins")
usersList = group.user_set.all()
How could you pull all users? I don't want to have to pick or assign a group.
你怎么能拉所有用户?我不想选择或分配一个组。
group = Group.objects.get() #Doesn't Work.
usersList = group.user_set.all()
采纳答案by Brandon
from django.contrib.auth.models import User
users = User.objects.all()
回答by Harish Verma
Django get user it's also simple method to get all user ,create user ,change password ,etc
Django获取用户它也是获取所有用户,创建用户,更改密码等的简单方法
from django.contrib.auth import get_user_model
user = get_user_model()
user.objects.all()
回答by Roshan Bagdiya
from django.contrib.auth.models import User
userList =User.objects.values()
will return values of all user in list format from Django User table. User.objects.all() will returns object.
将从 Django User 表中以列表格式返回所有用户的值。User.objects.all() 将返回对象。

