16

I was looking to do something like this, but for a Django management command: Python argparse: How to insert newline in the help text?

Community
  • 1
  • 1
Seán Hayes
  • 4,060
  • 4
  • 33
  • 48

2 Answers2

28

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
oglop
  • 1,175
  • 1
  • 9
  • 15
Seán Hayes
  • 4,060
  • 4
  • 33
  • 48
4

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")
OM Tiwari
  • 75
  • 2
  • 4
    This is not for a django management command, but Model field help text to be displayed in admin. – smido Mar 06 '20 at 09:42