您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – Django:需要用户电子邮件

5b51 2022/1/14 8:21:36 python 字数 2695 阅读 496 来源 www.jb51.cc/python

对于我的应用程序,应该要求用户的电子邮件字段.对于默认的用户模型,情况并非如此.所以我认为按照docs中的描述创建自定义用户模型是有意义的: If you’re starting a new project, it’s highly recommended to set up a custom user model, even if the defa

概述

对于我的应用程序,应该要求用户的电子邮件字段.对于认的用户模型,情况并非如此.所以我认为按照docs中的描述创建自定义用户模型是有意义的:

If you’re starting a new project,it’s highly recommended to set up a
custom user model,even if the default User model is sufficient for
you. This model behaves identically to the default user model,but
you’ll be able to customize it in the future if the need arises:

from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    email = models.EmailField(_('email address'),blank=False)

但是,我不确定这是否是实现这一目标的正确方法.

原因是here Django文档说:

Abstract base classes are useful when you want to put some common
information into a number of other models. You write your base class
and put abstract=True in the Meta class. This model will then not be
used to create any database table. Instead,when it is used as a base
class for other models,its fields will be added to those of the child
class. It is an error to have fields in the abstract base class with
the same name as those in the child (and Django will raise an
exception).@H_403_32@

我现在应该怎么做?

我在开始帖子中描述的方式应该有效.文档是错的:
https://code.djangoproject.com/ticket/29192

总结

以上是编程之家为你收集整理的python – Django:需要用户电子邮件全部内容,希望文章能够帮你解决python – Django:需要用户电子邮件所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶