Home > Back-end >  POST Method missing in 'Allowed' Django rest framework
POST Method missing in 'Allowed' Django rest framework

Time:08-22

This is what is showing when I go the rest framework page in my web browser

Allow: GET, HEAD, OPTIONS

My model.py is as follows:

class Note(models.Model):
    title =  models.CharField(max_length=120)
    description = models.CharField(max_length=600)
    def __str__(self):
        return self.title

These are my serializers.py :

class NoteSerializer(serializers.ModelSerializer):
    class Meta:
        model = Note
        fields = '__all__'

Lastly these are my views


class NotesViewset(viewsets.ModelViewSet):
    serializer_class = NoteSerializer
    queryset = Note.objects.all()

CodePudding user response:

you should add some function to work with the post request. I might be mistaken but as far I know you need to define "post" and/or "update", "partial_update", "destroy" for making changes to the data, these are not pre defined. You could use a generic view set for default implementations.

These are the viewset actions (documentation)

CodePudding user response:

Please add your urls.py. Are you using DefaultRouter?

  • Related