[Fixed]-Django command: How to insert newline in the help text?

29👍

From the documentation

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

By overriding create_parser method
you can set the formatter_class of the ArgumentParser:

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

3👍

You can insert the new line in help_text by entering the HTML
tag

For e.g.

name=models.Charfield(max_length=10, help_text="Enter First name or <br/> Enter full name")

Leave a comment