如何在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()),
]
答案 0 :(得分:1)
你没有。
str_extract_all(x,"_[[:digit:]]+$")
仅适用于@action
中的ViewSet
,GenericViewSet
,ModelViewSet
。