134👍
✅
from django.contrib.auth import get_user_model
User = get_user_model()
users = User.objects.all()
7👍
Try this:
from django.contrib.auth.models import User
all_users = User.objects.values()
print(all_users)
print(all_users[0]['username'])
all_users
will contain all the attributes of the user. Based upon your requirement you can filter out the records.
- [Django]-Django: Redirect to previous page after login
- [Django]-Django migration error :you cannot alter to or from M2M fields, or add or remove through= on M2M fields
- [Django]-Why does django's prefetch_related() only work with all() and not filter()?
6👍
Django get user it’s also simple method to get all user ,create user ,change password ,etc
from django.contrib.auth import get_user_model
user = get_user_model()
user.objects.all()
- [Django]-Detect django testing mode
- [Django]-Accessing dictionary by key in Django template
- [Django]-Trying to migrate in Django 1.9 — strange SQL error "django.db.utils.OperationalError: near ")": syntax error"
5👍
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]-Use Python standard logging in Celery
- [Django]-UUID as default value in Django model
- [Django]-Python Django Rest Framework UnorderedObjectListWarning
2👍
You can use this code
from django.contrib.auth.models import User
users = User.object.all()
- [Django]-Django: using <select multiple> and POST
- [Django]-How to reset Django admin password?
- [Django]-Django-allauth: Linking multiple social accounts to a single user
0👍
if your using Basic Token Authorization
please use this but it return a dictionary
from django.contrib.auth.models import User
users = User.objects.values()
- [Django]-Django staticfiles not found on Heroku (with whitenoise)
- [Django]-Writing a __init__ function to be used in django model
- [Django]-Django: Safely Remove Old Migrations?
Source:stackexchange.com