2024-04-19 16:21:46 发布
网友
如何从django中的auth_user表中获取用户id。假设用户名对我可用。
auth_user
用户没有后端,因此必须使用用户管理器(如果有自定义用户类,则使用BaseUserManager)
BaseUserManager.get_by_natural_key(username)
https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#django.contrib.auth.models.BaseUserManager
假设用户存在:
from django.contrib.auth.models import User User.objects.get(username=the_username).pk
用户没有后端,因此必须使用用户管理器(如果有自定义用户类,则使用BaseUserManager)
https://docs.djangoproject.com/en/1.6/topics/auth/customizing/#django.contrib.auth.models.BaseUserManager
假设用户存在:
相关问题 更多 >
编程相关推荐