django.contrib.auth.backends.py中对身份验证功能的困惑

时间:2015-07-26 03:07:58

标签: python django authentication

我想了解Integer.Parse()如何获取UserModel

authenticate

我的困惑在于# https://github.com/django/django/blob/master/django/contrib/auth/backends.py def authenticate(self, username=None, password=None, **kwargs): UserModel = get_user_model() if username is None: username = kwargs.get(UserModel.USERNAME_FIELD) try: user = UserModel._default_manager.get_by_natural_key(username) if user.check_password(password): return user except UserModel.DoesNotExist: # Run the default password hasher once to reduce the timing # difference between an existing and a non-existing user (#20760). UserModel().set_password(password)

中的get_module函数
get_user_model

并定义了# https://hdknr.github.io/docs/django/modules/django/contrib/auth.html#get_user_model def get_user_model(): "Return the User model that is active in this project" from django.conf import settings from django.db.models import get_model try: app_label, model_name = settings.AUTH_USER_MODEL.split('.') except ValueError: raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'") user_model = get_model(app_label, model_name) if user_model is None: raise ImproperlyConfigured("AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL) return user_model

get_model

由于# https://docs.djangoproject.com/en/1.8/_modules/django/db/models/ def make_alias(function_name): # Close function_name. def alias(*args, **kwargs): warnings.warn( "django.db.models.%s is deprecated." % function_name, RemovedInDjango19Warning, stacklevel=2) # This raises a second warning. from . import loading return getattr(loading, function_name)(*args, **kwargs) alias.__name__ = function_name return alias this_module = sys.modules['django.db.models'] for function_name in ('get_apps', 'get_app_path', 'get_app_paths', 'get_app', 'get_models', 'get_model', 'register_models'): setattr(this_module, function_name, make_alias(function_name)) 现在是get_module功能

的别名

我不知道如何

alias

获取get_module(app_label, model_name) 中指定的UserAccount模块,因为它等同于

AUTH_USER_MODEL

我似乎无法在

中找到加载功能
getattr(loading, `get_module`)(app_label, model_name)

有人可以帮帮我吗?感谢

0 个答案:

没有答案