./manage.py runserver (--option)← Ajoutez des options ici
-Je souhaite ajouter un nouveau traitement tout en conservant l'opération existante dans runserver
nom de l'application/management/commands/runserver.py
from django.contrib.staticfiles.management.commands.runserver import Command as RunCommand
class Command(RunCommand):
       
       help = "Commande elle-même(runserver)Explication etc."
       def add_arguments(self, parser):
           super().add_arguments(parser)
        
           parser.add_argument(
            'nom de l'option',    help='--Déclaration à côté de l'option à l'aide'
        )
      
      def handle(self, *args, **options):
          #Traitez ici
          super().handle(*args, **options)
-Dans l'argument de * parser.add_argument *, vous pouvez définir si l'option de commande à créer nécessite un argument. ・ Il existe d'autres éléments qui peuvent être définis avec des arguments
-Il semble que l'application créée ici doit être supérieure à l'application remplacée par INSTALLED_APPS dans les paramètres. (Voir [ici] pour plus de détails (https://docs.djangoproject.com/en/2.2/howto/custom-management-commands/#overriding-commands))
INSTALLED_APPS = [
    'app', #Changement
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
・ Cette fois, ajoutez avec --exemple
 ./manage.py runserver --help
usage: manage.py runserver [-h] [--ipv6] [--nothreading] [--noreload]
                           [--nostatic] [--insecure] [--example] [--version]
                           [-v {0,1,2,3}] [--settings SETTINGS]
                           [--pythonpath PYTHONPATH] [--traceback]
                           [--no-color] [--force-color]
                           [addrport]
Starts a lightweight Web server for development and also serves static files.
positional arguments:
  addrport              Optional port number, or ipaddr:port
optional arguments:
  -h, --help            show this help message and exit
  --ipv6, -6            Tells Django to use an IPv6 address.
  --nothreading         Tells Django to NOT use threading.
  --noreload            Tells Django to NOT use the auto-reloader.
  --nostatic            Tells Django to NOT automatically serve static files
                        at STATIC_URL.
  --insecure            Allows serving static files even if DEBUG is False.
  --example             #C'est l'option ajoutée cette fois
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.
  --force-color         Force colorization of the command output.
        Recommended Posts