1. Admin 自动注册全部 Model 字段 admin.py 1 2 3 4 5 6 7 8 9 10 # -*- coding: utf-8 -*- import inspect from django.contrib import admin from . import models for name, obj in inspect.getmembers(models): try: if inspect.isclass(obj): admin.site.register(getattr(models, name)) except Exception as e: pass 2. 获取全部 View Name 获取 Project 全部 View Name 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 from django.conf import settings from django.core.urlresolvers import RegexURLResolver, RegexURLPattern root_urlconf = __import__(settings.ROOT_URLCONF) all_urlpatterns = root_urlconf.urlpatterns VIEW_NAMES = [] # maintain a global list def get_all_view_names(urlpatterns): global VIEW_NAMES for pattern in urlpatterns: if isinstance(pattern, RegexURLResolver): get_all_view_names(pattern.url_patterns) #