djoser
djoser copied to clipboard
KeyError at /api/v1/users/set_username/
{ "current_password": "@Test111", "re_new_email": "[email protected]", "new_email": "[email protected]" }
Request Type: POST
@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.