Answers for "AttributeError: This QueryDict instance is immutable django"

0

AttributeError: This QueryDict instance is immutable django

#views.py
from rest_framework import generics


class Login(generics.CreateAPIView):
    serializer_class = MySerializerClass
    def create(self, request, *args, **kwargs):
        request.data._mutable = True
        request.data['username'] = "[email protected]"
        request.data._mutable = False

#serializes.py
from rest_framework import serializers


class MySerializerClass(serializers.Serializer):
    username = serializers.CharField(required=False)
    password = serializers.CharField(required=False)
    class Meta:
        fields = ('username', 'password')
Posted by: Guest on August-14-2021

Python Answers by Framework

Browse Popular Code Answers by Language