Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法使用Rest API进行POST_Python_Django - Fatal编程技术网

Python 无法使用Rest API进行POST

Python 无法使用Rest API进行POST,python,django,Python,Django,所以我可以很好地检索我的数据,但当我尝试发布时,我得到了 {"detail":"Method \"POST\" not allowed."} views.py class ClubFullList(generics.ListAPIView): serializer_class = ClubSerializer def get_queryset(self): return Club.objects.all() class ClubList(generics.L

所以我可以很好地检索我的数据,但当我尝试发布时,我得到了

{"detail":"Method \"POST\" not allowed."}
views.py

class ClubFullList(generics.ListAPIView):
    serializer_class = ClubSerializer

    def get_queryset(self):
        return Club.objects.all()

class ClubList(generics.ListAPIView):
    serializer_class = ClubSerializer

    def get_queryset(self):
        username = self.kwargs['username']
        return Club.objects.filter(abv=username)
models.py

class Club(models.Model):
        name = models.CharField(max_length=255)
        abv = models.CharField(max_length=255)
序列化程序.py

class ClubSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Club
        fields = ['name', 'abv']

我怎样才能解决这个问题

您正在一个只允许GET请求的端点上发送POST请求


ListAPIView
是一个只读的通用视图。要使用POST请求创建模型对象,请使用或。

您正在一个只允许GET请求的端点上发送POST请求

ListAPIView
是一个只读的通用视图。要使用POST请求创建模型对象,请使用或。

从:

用于表示模型实例集合的只读端点

如果要发布到端点,则需要使用不同的视图类。

来自:

用于表示模型实例集合的只读端点

如果要发布到端点,则需要使用不同的视图类