def auto_add_namespace(): path = os.path.dirname(os.path.abspath(__file__)) base_file = ".".join(path.split('\')[-2:]) n = 0 for module_name in os.listdir(path): file_path = os.path.join(path, module_name) if not os.path.isdir(file_path): continue if not os.path.exists(os.path.join(file_path, '__init__.py')): continue mod = os.path.join(path, module_name) for filename in os.listdir(mod): if os.path.exists(os.path.join(mod, "views")): if filename == "views": for f in os.listdir(os.path.join(mod, filename)): if f not in ["__init__.py", "serializers.py", "__pycache__"]: s = ".".join([base_file, module_name, "views", f.strip(".py")]) ns = import_string(s + ":ao_ns") api.add_namespace(ns) print("router number: ", n) auto_add_namespace()