Here is my code:
from django.core.management.base import BaseCommand, CommandError
import sys, os, shutil
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('--file', nargs='1', type=str)
def handle(self, *args, **options):
lists_file = options['file']
However, when I try to run the command with:
./manage.py: error: no such option: --file=test_lists.txt
I get an error:
Usage: ./manage.py create_test_lists [options]
./manage.py: error: no such option: --file
I have verified that test_lists.txt exists in the same directory as manage.py. In addition the file for my command is located at my_app/management/commands/create_test_lists.py which seems right. Any ideas as to what I'm doing wrong?
nargs
if it's just oneargparse.FileType
instread of str
Example:
import argparse
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('--file', type=argparse.FileType('r'))
def handle(self, *args, **options):
lists_file = options['file']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With