首页 > 解决方案 > 我怎样才能找到用户总数?

问题描述

我正在寻找一种方法来获取 Django 中的用户总数。我最好的猜测是:

模型.py

def homepage_view(request):
    context = {
        "users": Users.objects.all(),
    }
    return render(request=request, template_name='main/index.html', context=context)

html

{{users.count}}

我不知道如何将所有用户导入我的视图

标签: djangodjango-modelsdjango-templates

解决方案


我通过导入用户解决了这个问题

from django.contrib.auth.models import User


推荐阅读