How to Get all User in Django Framework?

Published On: 29/07/2022 | Category: Django Python


Hi Dev,

This article will give you example of django get all users example. you will learn django get all users example app. you can see django get all users example code. if you have question about django get all users example from user then I will give simple example with solution. you will do the following things for django list users command line.

In this tuts, First of all we can use get_user_model form django.contrib.auth to get user model.

let's see below simple example with output:

Example views.py
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth import get_user_model

# Create your views here.
def get_user(request):
    
    User = get_user_model()
    users = User.objects.all()
    print(users)

    return HttpResponse('')

I Hope It will help you....