Skip to content

Instantly share code, notes, and snippets.

@allieus
Last active December 29, 2015 12:59
Show Gist options
  • Save allieus/7674459 to your computer and use it in GitHub Desktop.
Save allieus/7674459 to your computer and use it in GitHub Desktop.
django-rest-framework 에서의 password2 처리
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
@kkorovesis
Copy link

KeyError password2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment