Py学习  »  Django

在源代码中找不到django函数

trevore23 • 4 年前 • 489 次点击  

我正在编写一个django应用程序并创建一个自定义用户模型。要做到这一点,我要从django.contrib.auth导入get_user_模型,这很好。但是,为了更好地理解事情,我试图在django源代码中找到这个函数,但是当我在git repo中访问django.contrib.auth时,我找不到它。

有人能告诉我哪里出了问题吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38341
 
489 次点击  
文章 [ 2 ]  |  最新文章 4 年前
Willem Van Onsem
Reply   •   1 楼
Willem Van Onsem    4 年前

你可以点击 [source] of the get_user_model function [Django-doc] . 这指的是显示 source code [Django-doc] :

def get_user_model():
    """
    Return the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )

在源代码目录中, auth 是一个目录,您可以在 __init__.py file [GitHub]

mbhargav294
Reply   •   2 楼
mbhargav294    4 年前