zoukankan      html  css  js  c++  java
  • django中从你的代码运行管理命令call_command

    # 主要用法就是调用django自定义的Command命令
    # 语法
    django.core.management.call_command(name,*args,**options)
    - name # 要调用的命令的名称或命令对象。除非测试需要对象,否则首选传递名称。
    - args # 命令接受的参数列表。参数传递给参数解析器,因此您可以使用与在命令行上相同的样式。例如call_command('flush', '--verbosity=0')
    - options # 命令行上接受的命名选项,选项被传递给命令而不触发参数解析器,这意味着你需要传递正确的类型。例如call_command('flush', verbosity=0)
    from django.core.management import call_command
    from django.core.management.commands import loaddata
    call_command('flush', verbosity=0, interactive=False)
    call_command('loaddata', 'test_data', verbosity=0)
    call_command(loaddata.Command(), 'test_data', verbosity=0)
    请注意,不带参数的命令选项作为关键字使用True或传递False,正如在interactive上面的选项中看到的那样。
    call_command('dumpdata', '--natural-foreign')
    call_command('dumpdata', natural_foreign=True)
    call_command('dumpdata', use_natural_foreign_keys=True)
    
  • 相关阅读:
    正则表达式在NLP中应用
    spring boot中 异常:Error resolving template "xxx", template might not exist or might not be accessible...解决办法
    毕业设计6
    毕业设计5
    毕业设计4
    毕业设计3
    毕业设计2
    毕业设计1
    支付宝架构
    Javaee应用架构
  • 原文地址:https://www.cnblogs.com/weiweivip666/p/15607781.html
Copyright © 2011-2022 走看看