2
TokenAuthentification을 내 django-rest-server
에 있습니다. 등록 후 login
은 완벽하게 작동하지만 이전 입력란으로 업데이트를 호출하면 더 이상 로그인 할 수 없습니다 (제공된 자격증 명으로 로그인 할 수 없음). 내가 도대체 뭘 잘못하고있는 겁니까?Django는 저장 후 로그인 할 수 없습니다.
업데이트 코드 :
class ClientSerializer(serializers.ModelSerializer):
username = serializers.CharField(source='user.username')
first_name = serializers.CharField(source='user.first_name')
last_name = serializers.CharField(source='user.last_name')
email = serializers.CharField(source='user.email')
password = serializers.CharField(source='user.password')
profile_photo = serializers.ImageField(source='details_sample.profile_photo', required=False)
class Meta:
model = Client
fields = ('id', 'username', 'first_name', 'last_name', 'email', 'password', 'profile_photo', 'phone')
def update(self, instance, validated_data):
if validated_data.get('user') is not None:
instance.user.set_password(validated_data['user'].get('password', instance.user.password))
instance.username = validated_data['user'].get('username', instance.user.password)
instance.first_name = validated_data['user'].get('first_name', instance.user.password)
instance.last_name = validated_data['user'].get('last_name', instance.user.password)
instance.user.save()
instance.phone = validated_data.get('phone', instance.phone)
instance.save()
return instance
로그인 URL :
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
토큰 생성 :
@receiver(post_init, sender=settings.AUTH_USER_MODEL)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)
더 이상 로그인 할 수 없다는 것을 의미합니까? –
@ArpitSolanki가 추가되었습니다. "제공된 자격 증명으로 로그인 할 수 없습니다." 답으로. 그러나 사용자 이름과 암호는 정확합니다. –