django 类列表实例化

一. 创建类

from rest_framework.views import APIView
class Group(APIView):
    
    def get(self,request):
        pass


class Role(APIView):
    def get(self, request):
        pass

二. 类实例化

v2 = [Role,Group,]
for item in v2:
    item()

三. importlib实例化

v1 = ["view.xxx.path.Role","view.xxx.path.Group",]
for item in v1:
     m = importlib.import_module('view.xxx.path')
     cls = getattr(m,'Role')
     cls()

 

posted @ 2018-02-07 16:28  Pythia丶陌乐  阅读(240)  评论(0编辑  收藏  举报