【问题标题】:Creating User using Djoser is not storing data for all fields (使用 Djoser 创建用户不会存储所有字段的数据(
【发布时间】:2021-09-20 01:58:19
【问题描述】:

我正在使用 DRF 创建一个 ReST API。

我正在使用 Djoser 进行用户管理。我正在使用默认的 django 用户模型,因为它符合我的目的。

当我点击端点注册新用户时,只存储用户名、密码和电子邮件。我传递了 first_name、last_name 和 is_staff 等所有数据,但只存储了用户名、密码和电子邮件。

我已附加 Djsoer 设置。

DJOSER = {
    'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
    'USERNAME_RESET_CONFIRM_URL': '#/username/reset/confirm/{uid}/{token}',
    'ACTIVATION_URL': '#/activate/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,
    'SEND_CONFIRMATION_EMAIL': True,
    'PASSWORD_CHANGED_EMAIL_CONFIRMATION': True,
    'USERNAME_CHANGED_EMAIL_CONFIRMATION': True,
    'USER_CREATE_PASSWORD_RETYPE': True, #Designed to propote good programming practice
    'SET_PASSWORD_RETYPE': True, #Designed to propote good programming practice
    'PASSWORD_RESET_CONFIRM_RETYPE': True, #Designed to propote good programming practice
    'LOGOUT_ON_PASSWORD_CHANGE' : True, #Note : Logout only works with token based authentication. djoser 2.10
    'PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND': False, #Please note that setting this to True will expose information whether an email is registered in the system
    'USERNAME_RESET_SHOW_EMAIL_NOT_FOUND': False, #Please note that setting this to True will expose information whether an email is registered in the system
    'token': 'djoser.serializers.TokenSerializer',
    'token_create': 'djoser.serializers.TokenCreateSerializer',
}

我做错了什么?

【问题讨论】:

    标签: django django-rest-framework django-registration djoser


    【解决方案1】:

    我对 Djoser 不太了解,但你可以使用 python 包 django-allauth 来自https://django-allauth.readthedocs.io/en/latest/installation.html

    在 django-allauth 中,您可以添加 first_name 和 last_name 以及许多其他类似的信息

    django-allauth features

    或者,如果您特别想添加 first_name、last_name 和 is_staff 以及任何其他个人信息,那么您可以在

    中创建关于此用户信息的特定模型

    models.py

    【讨论】:

    • 我研究过 django-allauth,但 django-allauth 包的问题是它不提供 ReST 端点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 2020-06-22
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    相关资源
    最近更新 更多