在Pycharm中以DEBUG模式在Django服务器上跳过系统检查 [英] Skip system checks on Django server in DEBUG mode in Pycharm
问题描述
我正在Pycharm中以调试模式运行django应用程序。
每次更改某些代码系统时,都会执行检查。
I am running django application in Pycharm in DEBUG mode. Each time when i change some code system checks are performed.
pydev debugger: process 2354 is connecting
Performing system checks...
是否有任何方法可以跳过系统检查/速度
Is there any way to skip system checks/speed up this checks?
更新:我想在代码更改后禁用系统检查,因为它们太慢了。
UPDATE: I want to disable system checks after changes in code, because they are too slow.
推荐答案
问题
不幸的是,没有命令行参数或设置,您只能打开才能将其关闭 runserver
中的检查。 通常,有-skip-checks
选项可以关闭系统检查,但对于没有用处runserver
。
The Problem
Unfortunately, there's no command-line argument or setting you can just turn on in order to turn off the checks in runserver
. In general, there's the --skip-checks
option which can turn off system checks but they are of no use for runserver
.
如果您阅读 runserver
命令的代码,则会看到它实际上会忽略 requires_system_checks
和 requires_migration_checks
标志,而是显式调用 self.check()
和 self.check_migrations()
在其 inner_run
方法,无论如何:
If you read the code of the runserver
command, you see that it essentially ignores the requires_system_checks
and requires_migration_checks
flags but instead explicitly calls self.check()
and self.check_migrations()
in its inner_run
method, no matter what:
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
命令,但会覆盖执行检查的方法:
A Solution
What you could do is derive your own run
command, which takes the runserver
command but overrides the methods that perform the checks:
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
下,其中< app>
是适合该应用程序的任何命令。然后您可以使用 ./ manage.py run
调用它,您将得到类似的东西:
You need to put this under <app>/management/commands/run.py
where <app>
is whatever appropriate app should have this command. Then you can invoke it with ./manage.py run
and you'll get something like:
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.
这篇关于在Pycharm中以DEBUG模式在Django服务器上跳过系统检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!