Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从 auth_userdjango 中的表中获取用户 ID。假设用户名对我可用。
auth_user
假设用户存在:
from django.contrib.auth.models import User User.objects.get(username=the_username).pk
用户没有后端,因此您必须使用 UserManager (或 BaseUserManager 如果您有自定义 User 类)
BaseUserManager.get_by_natural_key(username)
https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#django.contrib.auth.models.BaseUserManager