'Django argparse: Unrecognized Arguments --settings?

I've looked at the other SO threads about unrecognized argparse arguments, but none of them seem to match up with my situation.

Here's my argparse code, located at apps/create_pdf/management/commands/create_pdf.py:


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

class Command(BaseCommand):
    help = 'html to pdf for specified website.'

    def add_arguments(self, parser):
        print('cp#1')

        parser = argparse.ArgumentParser(description='html to pdf for specified website')
        parser.add_argument('-w', '--website', nargs =1, action = 'store', choices = ['SITE_1', 'SITE_2'], default='', help='site to be scraped.')
        args = parser.parse_args()

        print(args)
        breakpoint()

    def handle(self, *args, **options):
        print('cp#2')

        # create_pdf_from_html()

I run this from the terminal like so:

python3 manage.py create_pdf --website=SITE_1 --settings=server_config.settings

...and I'm getting this error:

manage.py: error: unrecognized arguments: create_pdf --settings=server_config.settings

The settings path is correct and if I'm not using argparse, everything runs fine.

What am I missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source