Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError at /api/v1/users/set_username/ #691

Open
Swe-HimelRana opened this issue Aug 28, 2022 · 2 comments
Open

KeyError at /api/v1/users/set_username/ #691

Swe-HimelRana opened this issue Aug 28, 2022 · 2 comments

Comments

@Swe-HimelRana
Copy link

{ "current_password": "@Test111", "re_new_email": "hotev52939@otodir.com", "new_email": "hotev52939@otodir.com" }

Request Type: POST

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

@Swe-HimelRana
Copy link
Author

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

@chapimenge3
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants