Tôi đang cố gắng sử dụng số call_command
của Django theo cách rất giống với this question without an answer.đối số call_command là bắt buộc
Con đường tôi đang gọi nó là:
args = []
kwargs = {
'solr_url': 'http://127.0.0.1:8983/solr/collection1',
'type': 'opinions',
'update': True,
'everything': True,
'do_commit': True,
'traceback': True,
}
call_command('cl_update_index', **kwargs)
Về lý thuyết, mà nên làm việc, theo the docs. Nhưng nó không hoạt động, nó chỉ không.
Dưới đây là phương pháp add_arguments
cho các lớp học chỉ huy của tôi:
def add_arguments(self, parser):
parser.add_argument(
'--type',
type=valid_obj_type,
required=True,
help='Because the Solr indexes are loosely bound to the database, '
'commands require that the correct model is provided in this '
'argument. Current choices are "audio" or "opinions".'
)
parser.add_argument(
'--solr-url',
required=True,
type=str,
help='When swapping cores, it can be valuable to use a temporary '
'Solr URL, overriding the default value that\'s in the '
'settings, e.g., http://127.0.0.1:8983/solr/swap_core'
)
actions_group = parser.add_mutually_exclusive_group()
actions_group.add_argument(
'--update',
action='store_true',
default=False,
help='Run the command in update mode. Use this to add or update '
'items.'
)
actions_group.add_argument(
'--delete',
action='store_true',
default=False,
help='Run the command in delete mode. Use this to remove items '
'from the index. Note that this will not delete items from '
'the index that do not continue to exist in the database.'
)
parser.add_argument(
'--optimize',
action='store_true',
default=False,
help='Run the optimize command against the current index after '
'any updates or deletions are completed.'
)
parser.add_argument(
'--do-commit',
action='store_true',
default=False,
help='Performs a simple commit and nothing more.'
)
act_upon_group = parser.add_mutually_exclusive_group()
act_upon_group.add_argument(
'--everything',
action='store_true',
default=False,
help='Take action on everything in the database',
)
act_upon_group.add_argument(
'--query',
help='Take action on items fulfilling a query. Queries should be '
'formatted as Python dicts such as: "{\'court_id\':\'haw\'}"'
)
act_upon_group.add_argument(
'--items',
type=int,
nargs='*',
help='Take action on a list of items using a single '
'Celery task'
)
act_upon_group.add_argument(
'--datetime',
type=valid_date_time,
help='Take action on items newer than a date (YYYY-MM-DD) or a '
'date and time (YYYY-MM-DD HH:MM:SS)'
)
Không có vấn đề gì tôi làm ở đây, tôi nhận được:
CommandError: Error: argument --type is required
Bất kỳ ý tưởng? Nếu bạn thực sự tò mò, bạn có thể see the entire code here.
action = store_true và default = False mâu thuẫn với nhau. 'store_true' là bí danh cho' store_const' với 'const = True' – Incognos