Run bash file from Django views in Windows

Viewed 20

I would like to run a bash file from a class written in views file of Django. I have tried many ways but didn't seem to work. So can you suggest some effective method for this ? I am mentioning below the code I am using.

class UploadImage(CreateView):
    model = ImageModel
    template_name = 'deploy/imagemodel_form.html'
    fields = ["image"]

    def post(self,request,*args,**kwargs):
      form = ImageUploadForm(request.POST,request.FILES)
      if form.is_valid():
         img = request.FILES.get('image')
         img_instance = ImageModel(image=img)
         img_instance.save()

         uploaded_img = ImageModel.objects.filter().last()
         img_in_bytes = uploaded_img.image.read()
         img = im.open(io.BytesIO(img_in_bytes))
         subprocess.call('./run.sh',shell=True)

In run.sh file I am just running another .py file.

0 Answers
Related