我试图哈希密码,一旦创建用户和我使用Django Rest
。但是,我得到了一个错误时,试图创建它。
{
"non_field_errors": [
"Invalid data. Expected a dictionary, but got str."
]
}
- 一米一米一**
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['username', 'first_name', 'last_name', 'email', 'active',
'admin', 'date_joined', 'password', 'partner']
- 一米二米一x**
class UserViewset(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
filter_backends = (filters.DjangoFilterBackend,)
def create(self, request, *args, **kwargs):
user = User.objects.all()
serializer = UserSerializer(
user, make_password(request.data['password']))
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data)
# return HttpResponse(user)
先谢了...
2条答案
按热度按时间f2uvfpb91#
啊我找到了答案xD
vwkv1x7d2#