2

I get an error when I run the command shown in the image below

enter image description here

python manage.py shell <processing.py 66

error is

usage: manage.py shell [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
                   [--pythonpath PYTHONPATH] [--traceback] [--no-color]
                   [--plain] [--no-startup] [-i {ipython,bpython,python}]
                   [-c COMMAND]

i think its not the right way to pass arguments while using shell. i cannot directly write

python processing.py

because i am using database filtering and so i have to use shell.

this is my processing.py

import os
import sys
from webapp.models import status


dirname = sys.argv[1]

print(os.getcwd())
sta = status.objects.filter(status_id=66)[0]
sta.status = True
sta.save()
print(sta.status)

thanks in advance

1

1 Answer 1

5

It looks like you want to create a custom management command, as mentioned in comments. Here's an example of one, which will print a passed command line argument, which should be placed in an app in a location like myapp/management/commands/say.py and called with python manage.py say --printme StackOverFlow:

from django.core.management.base import BaseCommand


class Command(BaseCommand):
    """
    This command will print a command line argument.
    """
    help = 'This command will import locations from a CSV file into the hivapp Locations model.'

    def add_arguments(self, parser):
        parser.add_argument(
            '--printme',
            action='store',
            dest='printme',
            default="Hello world!",
            help='''The string to print.'''
        )

    def handle(self, *args, **options):
        print(options['printme'])

You could pass a file name to iterate over with a list of command to run, although incorporate the commands into your command would be safer. Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.