我正在创建一个基于Web的应用程序,其中我需要以模板方式获取所有注册用户的列表。我使用django.contrib.auth模型来管理没有组的用户数据库。我无法找到https://docs.djangoproject.com/en/dev/topics/auth/中返回views.py中所有用户列表的任何方法
答案 0 :(得分:4)
将相应的查询集传递给您的模板:
from django.contrib.auth.models import User
from django.shortcuts import render
def foo(request):
return render(request,'users.html',{'users': User.objects.all()})
或者,如果这是您需要的所有模板,请写一个template context processor并将其添加到那里。