djangoauthapi1's Introduction
djangoauthapi1's People
Forkers
suprit-kumar champgourav007 harshilpatel007 shoebshah64 arafatcse16 mozsocia surajotari28 nareshcp360 thanhcoral tanveer-pucit itglobtech ahmedayaz eng-yuri89 sharjil-aditatech anonymous6419 rak1b sourendro noman-8560 muyiwadosunmu harshkaithwas shezziii mayank-chaudhari9 sagar746 kabikandel abhishekkannur thecheenee vishnu2646 ahahrukh shubhamk2014 michaelkigen arjunsharma1234 abhijitkumarin eoderinde serajsid786 sudhanshuweb3 divad437 vipulghadi imdad-rakib somesh140 rakesh835 sonawanekuldeepdjangoauthapi1's Issues
Serializer class causes issue saying User() has not attribute password2
Issue Description :
mysite_web | Attributes are : OrderedDict([('password', 'root'), ('password2', 'root')])
mysite_web | Internal Server Error: /auth/reset_password/
mysite_web | Traceback (most recent call last):
mysite_web | File "/usr/local/lib/python3.11/site-packages/rest_framework/serializers.py", line 962, in create
mysite_web | instance = ModelClass._default_manager.create(**validated_data)
mysite_web | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mysite_web | File "/usr/local/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
mysite_web | return getattr(self.get_queryset(), name)(*args, **kwargs)
mysite_web | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mysite_web | File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 656, in create
mysite_web | obj = self.model(**kwargs)
mysite_web | ^^^^^^^^^^^^^^^^^^^^
mysite_web | File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 567, in __init__
mysite_web | raise TypeError(
mysite_web | TypeError: User() got unexpected keyword arguments: 'password2'
mysite_web |
mysite_web | During handling of the above exception, another exception occurred:
Use update instead of save when saving new password
In below code, we are using .save() method. But as a standard practice, we should rather .update() the password.
class UserChangePasswordSerializer(serializers.Serializer):
password = serializers.CharField(max_length=255, style={'input_type':'password'}, write_only=True)
password2 = serializers.CharField(max_length=255, style={'input_type':'password'}, write_only=True)
class Meta:
fields = ['password', 'password2']
def validate(self, attrs):
password = attrs.get('password')
password2 = attrs.get('password2')
user = self.context.get('user')
if password != password2:
raise serializers.ValidationError("Password and Confirm Password doesn't match")
user.set_password(password)
user.save()
return attrs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.