GenericAPIView中的嵌套操作

时间:2019-03-06 16:58:25

标签: python django django-rest-framework

如何在Django Rest框架的GenericAPIView中创建新的嵌套路由 用于启用“ report / tasks / export_excel”之类的API URL

视图集


class TaskReportViewSet(generics.GenericAPIView):
    queryset = TiempoOperacion.objects.all()
    pagination_class = StandardResultsSetPagination
    serializer_class = TiempoOperacionSerializer

    def get(self, request):
    """
    Some code for 'get' request ...
    """

    @action(detail=False, methods=['GET'])
    def export_excel(self, request):
        sheet = excel.pe.Sheet([[1, 2],[3, 4]])
        return excel.make_response(sheet, "csv")

网址


urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^report/tasks/', TaskReportViewSet.as_view()),
]

1 个答案:

答案 0 :(得分:1)

你没有。

str_extract_all(x,"_[[:digit:]]+$") 仅适用于@action中的ViewSetGenericViewSetModelViewSet