'str'对象在Django中没有属性'as_view'

时间:2020-09-03 02:46:03

标签: django django-rest-framework

我在类中调用一个类视图。Call_view的值是“ InsertionOrder”,但是直接写“ InsertionOrder”是行不通的。值是动态的,所以我不能直接写“ InsertionOrder”。该怎么做? >

错误显示:“ str”对象在django中没有属性“ as_view”

class GenericDetailView(APIView):

    def put(self, request,pk, format=None):
        url_name = request.resolver_match.url_name
        call_view = url_name.split("_")[0].title().replace('-', '')
        return call_view.as_view()(request._request, format)        this does not
        # return InsertionOrder.as_view()(request._request, format)   this works
class InsertionOrder(APIView):
         #Code goes on

0 个答案:

没有答案