-1

I want to run an external python file

the Django.view code is as follows:


def generate(request):
    a=int(request.POST["status"])
    b=int(request.POST["level"])
    run(['python', 'water.py',a,b])

I have imported this water.py file from my app I want to pass these a and b values to my water.py file so that the water.py file can run in the background and can create a CSV file but I don't know how to pass these value my water.py code is as follows

from time import time
import sys
from __main__ import*




# trying to pass those values here 
x,current_level=sys.argv[1],sys.argv[2]

but when I try to pass the value in this way I get error list index out of range is there any better way to tackle with this problem please suggest it would be very helpful

1 Answers1

0

Generally, according to django you should include the python code in the view itself if possible. Django views helps to deal with models, reverse or redirect or call urls and renders the templates.

We can't run python seperately in Django application. In order to do that, there are some ways to do it. One of those easiest ways to do it is writing a basic Django command and call it from the django view. In this way we can send the parameters to the django command from the view.

Siva Sankar
  • 1,672
  • 1
  • 9
  • 16