Python Forum
Is it possible to perform a PUT request by passing a req body instead of an ID
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to perform a PUT request by passing a req body instead of an ID
I'm working on a Project using Python(3), Django(1.11) and DRF(3.6) in which I have to perform a PUT request by passing an Object instead of an ID.

Here are my
class Actor(models.Model):
    id = models.CharField(primary_key=True, max_length=255)
    login = models.CharField(max_length=255)
    avatar_url = models.URLField(max_length=500)

class Repo(models.Model):
    id = models.CharField(primary_key=True, max_length=255)
    name = models.CharField(max_length=255)
    url = models.URLField(max_length=500)

class Event(models.Model):
    id = models.CharField(primary_key=True, max_length=255)
    type = models.CharField(max_length=255)
    actor = models.ForeignKey(Actor, related_name='actor')
    repo = models.ForeignKey(Repo, related_name='repo')
    created_at = models.DateTimeField()
And here are my
class ActorSerializer(serializers.ModelSerializer):
    class Meta:
        model = Actor
        fields = ('id', 'login', 'avatar_url')
        read_only_fields = ('id', 'login')

    def update(self, instance, validated_data):
        instance.avata_url = validated_data.get('avatar_url', instance.avatar_url)
        return instance

class RepoSerializer(serializers.ModelSerializer):
    class Meta:
        model = Repo
        fields = ('id', 'name', 'url')

class EventModelSerializer(serializers.ModelSerializer):
    actor = ActorSerializer(many=False)
    repo = RepoSerializer(many=False)

    class Meta:
        model = Event
        fields = ('id', 'type', 'actor', 'repo', 'created_at')
        depth = 1

    def create(self, validated_data):
        actor = validated_data.pop('actor')
        repo = validated_data.pop('repo')
        actor = Actor.objects.create(**actor)
        repo = Repo.objects.create(**repo)
        return Event.objects.create(actor=actor, repo=repo, **validated_data)
And here's my
url(r'^actors/$', views.ActorView.as_view(), name='actors'),
And finally here's the
class ActorView(generics.GenericAPIView):
    serializer_class = ActorSerializer
    queryset = Event.objects.all()

    def update(self):
        actor = Event.objects.filter('id'))
        return HttpResponse(actor)
When I make a PUT request to the /actors and pass an object in the request body via Postman, it says Method Put not allowed.
how can I make the PUT request by passing a body object?

Possibly Related Threads…
Thread Author Replies Views Last Post
  [BeautifulSoup] Find </body>? Winfried 2 240 May-15-2023, 10:41 AM
Last Post: Winfried
  Passing Request objects to a serializer in DRF Dexty 0 1,091 Aug-15-2022, 04:51 AM
Last Post: Dexty
  Get html body of URL rama27 6 2,638 Aug-03-2020, 02:37 PM
Last Post: snippsat
  How to perform a successful login(signin) through Requests in Python Kalet 1 1,954 Apr-24-2020, 01:44 AM
Last Post: Larz60+
  How to perform predictions on a data in csv file using Flask? manjusavanth 0 4,134 May-23-2018, 09:03 AM
Last Post: manjusavanth
  In CSV, how to write the header after writing the body? Tim 18 12,650 Jan-06-2018, 01:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020