【发布时间】:2019-03-04 07:01:43
【问题描述】:
我的 ACTION 视图不起作用。
怎么传args不只是pk?
我使用的是基于函数的 api,例如
基于函数的 API 视图(一)
{host}:{port}/api/food/<year>/<month>/<day>/
现在,我有模型 Food 的新视图。
视图集(2)
{host}:{port}/food/
我希望将这个 api 集成到一个 ModelViewSet,所以我喜欢下面。
我想要什么 (1) + (2)
{host}:{port}/food/files/<year>/<month>/<day>/
{host}:{port}/food/
我的代码
class FoodViewSet(viewsets.ModelViewSet):
queryset = Food.objects.all()
permission_classes = [blahblah]
authentication_classes = [blahblah]
def list(self, request, *args, **kwargs):
...
return Response(blahblah)
def create(self, request, *args, **kwargs):
...
return Response(blahblah)
@action(['GET'], detail=True)
def files(self, request, year, month, day):
...
return Response(blahblah)
【问题讨论】:
标签: python django api django-rest-framework url-routing