散列密码,请致电:
make_password(origin_password)
示例 serializers.py :
from rest_framework import serializersfrom django.contrib.auth.models import Userfrom django.contrib.auth.hashers import make_passwordclass UserSerializer(serializers.HyperlinkedModelSerializer): password = serializers.CharField( write_only=True, required=True, help_text='Leave empty if no change needed', style={'input_type': 'password', 'placeholder': 'Password'} ) class meta: model = User fields = ('url', 'username', 'email', 'password') def create(self, validated_data): validated_data['password'] = make_password(validated_data.get('password')) return super(UserSerializer, self).create(validated_data)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)