Difference between revisions of "Django Management command"

From RHS Wiki
Jump to navigation Jump to search
(Created page with "app_dir/management/commands/cmdname.py<syntaxhighlight lang="python3"> from django.core.management.base import BaseCommand, CommandError class Command(BaseCommand): def...")
Tag: visualeditor
 
m
Tag: visualeditor
 
Line 5: Line 5:
 
class Command(BaseCommand):
 
class Command(BaseCommand):
 
     def add_arguments(self, parser):
 
     def add_arguments(self, parser):
         pass
+
         parser.add_argument('path', help='File path')
  
 
     def handle(self, *args, **options):
 
     def handle(self, *args, **options):
         pass
+
         print(f'{options['path']}')
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 08:38, 27 April 2020

app_dir/management/commands/cmdname.py

from django.core.management.base import BaseCommand, CommandError


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('path', help='File path')

    def handle(self, *args, **options):
        print(f'{options['path']}')