How to give the client argument in django management commands?

I have a function in django management commands that should take a url as an argument

class Command(BaseCommand):
    help = u'Enter the url'
    def add_arguments(self, parser):
        parser.add_argument('url',type=str,help=u'Enter the url')

    def handle(self,*args,**kwargs):
        url = kwargs['url']
        main(url)

it doesn't matter what the function is, everything in it works when a command is called through the terminal

but I have a question, how can I implement this into the client part? I want the user to enter a url and it is passed to the function.

What are the ways to pass user arguments to django management commands?

the solution turned out to be very simple

you just create a form unrelated to the model, create the fields that you need as an argument in your function, and then pass the data from the form to your command

def index(request):
    if request.method == 'POST':
        form = AddFilmUrl(request.POST)
        if form.is_valid():
            url = form.cleaned_data.get('url')
            management.call_command('parse',url)
    else:
        form = AddFilmUrl()
    return render(request, 'addfilm.html', {'form':form,})
Back to Top