gpt4 book ai didi

python - 为什么需要在 Tastypie 的 allowed_methods 列表和详细的 allowed_methods 中添加 'POST' 方法?

转载 作者:太空宇宙 更新时间:2023-11-04 05:49:56 42 4
gpt4 key购买 nike

class EntryResource(ModelResource):
user = fields.ForeignKey(UserResource, 'user')

class Meta:
queryset = Entry.objects.all()
list_allowed_methods = ['get','post']
detail_allowed_methods = ['post']
resource_name = 'myapp/entry'

为什么需要在 detail_allowed_methods 中添加“POST”,因为我评论 detail_allowed_methods “POST”工作正常......!

最佳答案

它工作正常,因为在注释掉 detail_allowed_methods 时,Tastypie 回落到它的默认值,即:

['get', 'post', 'put', 'delete', 'patch']

因此,注释 detail_allowed_methods 不会有任何作用。如果您想禁用所有方法,请将其值设置为空列表:

detail_allowed_methods = []

See Tastypie docs .

关于python - 为什么需要在 Tastypie 的 allowed_methods 列表和详细的 allowed_methods 中添加 'POST' 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30731395/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com