[Answered ]-Change script run from commandline to django view

1👍

As you haven’t provided any details about the script, I’m assuming there is a function inside that takes the filename and a model name as parameters and does the work when invoked from the terminal. You can simply move that function to a controller and call it with both the parameters on request.

Django has a whole section in their documentation explaining how to do it.

1👍

From my experience you can do anything you would do on a regular python script inside a Django view. For example :

#! python3
# -*-coding:utf-8 -*

from django.shortcuts import HttpResponse
import os

def myView(request):
    f = open('file.cvs', 'w')
    f.write('Whatever you want')
    f.close()
return HttpResponse('Done.')

You can put conditions and loops, so you should be able to put your entire script as a view like that.

Leave a comment