Как верно прописать путь, чтобы в Django запускался файл командой из консоли?
Должна отработать вот это задача:
(my-venv) $ python manage.py tasks_read_from_file --file input.txt
task_read_from_file.py
#!/usr/bin/env python
# coding: utf-8
from django.core.management import BaseCommand
from datetime import datetime
from tasks.models import TodoItem
class Command(BaseCommand):
help = u"Read tasks from file (one line = one task)and save them to db"
def add_arguments(self, parser):
parser.add_argument('--file', dest='input_file', type=str)
def handle(self, *args, **options):
now = datetime.now(timezone.utc)
file_path = "/~/Home/ASITES/python/10/m10/M8-9-10/todoapp/tasks/management/commands/input.txt"
my_file = open(file_path, 'r')
for t in my_file:
t = TodoItem(description=t, created=now)
t.safe()
response = HttpResponse(my_file.read(), mimetype='text/plain')
response['Content-Disposition'] = 'inline;filename=input.txt'
return response
В консоли:
(my-venv) user@user-RC530-RC730:~/Home/ASITES/python/10/m10/M8-9-10/todoapp$ python manage.py tasks_read_from_file file input.txt
usage: manage.py tasks_read_from_file [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color]
manage.py tasks_read_from_file: error: unrecognized arguments: file input.txt
(my-venv) user@user-RC530-RC730:~/Home/ASITES/python/10/m10/M8-9-10/todoapp$ (my-venv) $ python manage.py tasks_read_from_file --file input.txt
bash: синтаксическая ошибка рядом с неожиданным маркером «$»