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()