python - Django 命令 : How to insert newline in the help text?

标签 python django argparse

我想做这样的事情,但对于 Django 管理命令: Python argparse: How to insert newline in the help text?

最佳答案

来自documentation

You can customize the instance by overriding this method and calling super() with kwargs of ArgumentParser parameters.

通过覆盖 create_parser 方法 您可以设置 ArgumentParserformatter_class:

from argparse import RawTextHelpFormatter
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    def create_parser(self, *args, **kwargs):
        parser = super(Command, self).create_parser(*args, **kwargs)
        parser.formatter_class = RawTextHelpFormatter
        return parser

关于python - Django 命令 : How to insert newline in the help text?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35470680/

相关文章:

python - 如何在 Selenium 的下拉列表中选择项目

python - Django 2 - 如何使用电子邮件确认和 CBV 注册用户?

Python argparse 无法将十六进制格式解析为 int 类型

python - Spyder python编辑器: turn off whole-line tab when tabbing mid-line

python - 如何在python中实现队列的深复制

python - Python 上的随机模块

python - 从 Django 模板标签的变量中分割字符串

Python PIL 和 StringIO

Python argparse store_true 并在一个参数中存储 optional

python argparse 不显示正确的帮助信息