How to get user id from auth_user table in django?

how to get user id from auth_user table in django. Suppose the username is available to me.

+4
source share
2 answers

Assuming the user exists:

 from django.contrib.auth.models import User User.objects.get(username=the_username).pk 
+11
source

The user does not have a backend, so you should use the UserManager (or BaseUserManager if you have a user class of the user)

 BaseUserManager.get_by_natural_key(username) 

https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#django.contrib.auth.models.BaseUserManager

+1
source

All Articles