Last active
December 29, 2015 12:59
-
-
Save allieus/7674459 to your computer and use it in GitHub Desktop.
django-rest-framework 에서의 password2 처리
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import User | |
from rest_framework import serializers | |
class UserSerializer(serializers.ModelSerializer): | |
password2 = serializers.CharField() | |
def validate_password2(self, attrs, source): | |
password2 = attrs.pop(source) | |
if attrs['password'] != password2: | |
raise serializers.ValidationError('password mismatch') | |
return attrs | |
def to_native(self, obj): | |
self.fields.pop('password2') | |
return super(UserSerializer, self).to_native(obj) | |
class Meta: | |
model = User |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
KeyError password2