向命令中添加参数的正确方法:
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'html to pdf for specified website.'
def add_arguments(self, parser):
parser.add_argument('-w', '--website', nargs =1, action = 'store', choices = ['SITE_1', 'SITE_2'], default='', help='site to be scraped.')
def handle(self, *args, **options):
print(options['website'])
# create_pdf_from_html()