问题
不幸的是,没有命令行参数或设置可以打开以关闭检查runserver
. 一般来说,有--skip-checks
可以关闭系统检查的选项,但它们没有用runserver
.
如果您阅读了代码runserver
命令,你会发现它基本上忽略了requires_system_checks
and requires_migration_checks
标志但显式调用self.check()
and self.check_migrations()
in its inner_run method https://github.com/django/django/blob/1.10.5/django/core/management/commands/runserver.py#L110,无论如何:
def inner_run(self, *args, **options):
[ Earlier irrelevant code omitted ...]
self.stdout.write("Performing system checks...\n\n")
self.check(display_num_errors=True)
# Need to check migrations here, so can't use the
# requires_migrations_check attribute.
self.check_migrations()
[ ... more code ...]
一个办法
你能做的是衍生出你自己的run
命令,该命令需要runserver
命令但覆盖执行检查的方法:
from django.core.management.commands.runserver import Command as RunServer
class Command(RunServer):
def check(self, *args, **kwargs):
self.stdout.write(self.style.WARNING("SKIPPING SYSTEM CHECKS!\n"))
def check_migrations(self, *args, **kwargs):
self.stdout.write(self.style.WARNING("SKIPPING MIGRATION CHECKS!\n"))
你需要把它放在下面<app>/management/commands/run.py
where <app>
任何适当的应用程序都应该具有此命令。然后你可以调用它./manage.py run
你会得到类似的东西:
Performing system checks...
SKIPPING SYSTEM CHECKS!
SKIPPING MIGRATION CHECKS!
January 18, 2017 - 12:18:06
Django version 1.10.2, using settings 'foo.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.