djoser icon indicating copy to clipboard operation
djoser copied to clipboard

KeyError at /api/v1/users/set_username/

Open Swe-HimelRana opened this issue 2 years ago • 2 comments

{ "current_password": "@Test111", "re_new_email": "[email protected]", "new_email": "[email protected]" }

Request Type: POST

Screen Shot 2022-08-29 at 3 43 34 AM

Swe-HimelRana avatar Aug 28 '22 21:08 Swe-HimelRana

Screen Shot 2022-08-29 at 3 46 54 AM

Swe-HimelRana avatar Aug 28 '22 21:08 Swe-HimelRana

@Swe-HimelRana

I think you didn't update the USERNAME Field in your model. If you want to use email as a username you must change the USERNAME field.

Djoser uses the get_user_model method to get the User model of the project so after that it uses the field called USERNAME_FIELD from the model like below.

new_username = serializer.data["new_" + User.USERNAME_FIELD]

So this time I saw your data is new_email and djoser is looking for new_username. To fix this

class User(...):
  ....
  ...
  USERNAME_FIELD = 'email'
  

After that, it will be fixed hopefully.

chapimenge3 avatar Dec 31 '22 17:12 chapimenge3