【问题标题】:What is the model attached to django UserCreationForm()django UserCreationForm() 附加的模型是什么
【发布时间】:2020-10-25 08:40:18
【问题描述】:

我已经阅读了 UserCreationForm() 的官方文档。我正在尝试访问我在其他模型中创建的用户。我调用什么模型来访问我在 UserCreationForm() 中创建的用户?简而言之,它们是我可以调用以访问用户模型的默认身份验证模型吗?

【问题讨论】:

    标签: django django-models django-authentication


    【解决方案1】:

    我应该调用什么模型来访问我在UserCreationForm() 中创建的用户?

    正如我们在source code [GitHub] 中看到的,它使用User 模型:

    from django.contrib.auth.models import User
    
    # …
    
    class UserCreationForm(forms.ModelForm):
    
        # …
    
        class Meta:
            model = User
            fields = ("username",)
            field_classes = {'username': UsernameField}
    
        # …

    因此,您可以使用以下方法导入此模型:

    from django.contrib.auth.models import <b>User</b>

    documentation on the User 指定在此模型上定义的字段和方法。

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 2014-04-27
      • 2013-05-09
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      相关资源
      最近更新 更多