我热衷于学习Django的资源,从底层建立我的技能。你知道吗
在用户模型中,它具有password属性。使用命令from django.contrib.auth.models import User
导入模型
我检查了模块django/models.py,没有找到password = models.CharField()
,但最终在django/base_user.py中找到了它
class AbstractBaseUser(models.Model):
password = models.CharField(_('password'), max_length=128)
last_login = models.DateTimeField(_('last login'), blank=True, null=True)
有趣的是,AbstractBaseUser
和BaseUserManager
被封装为一个单独的模块,而不是合并到models.py
中,即使代码只有139行长。你知道吗
在base_user.py
中,它声称
""" This module allows importing AbstractBaseUser even when django.contrib.auth is not in INSTALLED_APPS."""
我无法理解它的意思。你知道吗
这样设计模块有什么好处?你知道吗
git blame
可以成为回答此类问题的有用工具。你知道吗如果您将^{} 归咎于git,那么您可以看到注释是添加在this commit中的,它是ticket 24564的一部分。你知道吗
正如那张罚单所解释的,如果您想从
django.contrib.auth.models
导入AbstractBaseUser
,您必须将django.contrib.auth
添加到INSTALLED_APPS
。这是因为模块包含非抽象模型,如User
。你知道吗因此,它被移动到一个单独的模块中,这样就可以导入它,而无需将
django.contrib.auth
添加到INSTALLED_APPS
。你知道吗相关问题 更多 >
编程相关推荐