django 源码阅读二 命令check
2016-03-28 00:00
369 查看
摘要: 查看django-admin check 命令
接着昨天的看 源码阅读一
上次看的django-admin 命令下只能执行help 跟一个version。 这次看看check 命令执行流程
要运行要先配置 一个setting。 你可以用已有项目里面的配置文件
我直接复制一个配置文件到 django-admin.py 的这个文件下面,并且删掉一些东西
只剩一个 SECRET_KEY 配置。
并且在运行文件加上一行 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
结构变成这样了
先运行一下结果是:System check identified no issues (0 silenced).
搞个断点调试看代码。
接着昨天的看 源码阅读一
上次看的django-admin 命令下只能执行help 跟一个version。 这次看看check 命令执行流程
要运行要先配置 一个setting。 你可以用已有项目里面的配置文件
我直接复制一个配置文件到 django-admin.py 的这个文件下面,并且删掉一些东西
""" Django settings for Attendance_system project. Generated by 'django-admin startproject' using Django 1.9.1. For more information on this file, see https://docs.djangoproject.com/en/1.9/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.9/ref/settings/ """ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '3$j)!r#3v_$s96277jyd)hv!2irwzgvkyr8g6c0g6b#cuwt@0='
只剩一个 SECRET_KEY 配置。
并且在运行文件加上一行 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
结构变成这样了
先运行一下结果是:System check identified no issues (0 silenced).
搞个断点调试看代码。
def execute(self): """ Given the command-line arguments, this figures out which subcommand is being run, creates a parser appropriate to that command, and runs it. """ try: subcommand = self.argv[1] # 如果没有传参数就默认输出help except IndexError: subcommand = 'help' # Display help if no arguments were given. # Preprocess options to extract --settings and --pythonpath. # These options could affect the commands that are available, so they # must be processed early. parser = CommandParser(None, usage="%(prog)s subcommand [options] [args]", add_help=False) parser.add_argument('--settings') parser.add_argument('--pythonpath') parser.add_argument('args', nargs='*') # catch-all try: options, args = parser.parse_known_args(self.argv[2:]) handle_default_options(options) except CommandError: pass # Ignore any option errors at this point. no_settings_commands = [ 'help', 'version', '--help', '--version', '-h', 'compilemessages', 'makemessages', 'startapp', 'startproject', ] try: settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc # A handful of built-in management commands work without settings. # Load the default settings -- where INSTALLED_APPS is empty. if subcommand in no_settings_commands: settings.configure() if settings.configured: # Start the auto-reloading dev server even if the code is broken. # The hardcoded condition is a code smell but we can't rely on a # flag on the command class because we haven't located it yet. if subcommand == 'runserver' and '--noreload' not in self.argv: try: autoreload.check_errors(django.setup)() except Exception: # The exception will be raised later in the child process # started by the autoreloader. Pretend it didn't happen by # loading an empty list of applications. apps.all_models = defaultdict(OrderedDict) apps.app_configs = OrderedDict() apps.apps_ready = apps.models_ready = apps.ready = True # In all other cases, django.setup() is required to succeed. 注意这个注释。 else: django.setup() # check 命令要求这个必须要运行成功。主要做检查 加载 判断模块是否重名等等。 # 有兴趣可以跳进去看看 self.autocomplete() if subcommand == 'help': if '--commands' in args: sys.stdout.write(self.main_help_text(commands_only=True) + '\n') elif len(options.args) < 1: sys.stdout.write(self.main_help_text() + '\n') else: self.fetch_command(options.args[0]).print_help(self.prog_name, options.args[0]) # Special-cases: We want 'django-admin --version' and # 'django-admin --help' to work, for backwards compatibility. elif subcommand == 'version' or self.argv[1:] == ['--version']: sys.stdout.write(django.get_version() + '\n') elif self.argv[1:] in (['--help'], ['-h']): sys.stdout.write(self.main_help_text() + '\n') else: self.fetch_command(subcommand).run_from_argv(self.argv) # 程序运行进入这里 # 调用management->commands->check.py 这个文件。 然后就进行了各种check。
相关文章推荐
- Django-Form表单(验证、定制、错误信息、Select)
- 2016/3/27 分页 共X条数据 本页x条 本页从x-y条 x/y页 首页 上一页 123456 下一页 末页 pagego echo $page->fpage(7,6,5,4,3,2,1,0);
- golang笔记——并发
- Django进阶(路由系统、中间件、缓存、Cookie和Session、Ajax发送数据
- 在Google Maps 上点击标签显示说明并保持不消失
- 在Google Maps 上点击标签后显示说明
- 如何在Google Maps 添加多个标记
- Google开源单元测试框架Google Test:VS2012 配置
- golang笔记——函数与方法
- HDU Let's go to play
- 如何在 Google 地图中添加标记和说明
- 启动Genymotion模拟器时,显示The virtual device got no IP address
- gone fishing
- HDU--1533--Going Home--KM算法
- Go语言学习(九)文件操作
- 【Algorithm】选择排序法
- 初识google多语言通信框架gRPC系列(二)编译gRPC
- Google Test
- EM算法(Expectation Maximization Algorithm)
- Google Maps API3 之 Hello World