1👍
You could use subprocess
module to run command and take the output.
Update 1
Example view:
import subprocess
def runCmd(request):
cmd = request.POST.get('cmd')
param = request.POST.get('param')
codeDir = '/path/to/py/file/'
absoluteCodePath = codeDir + cmd + '.py'
result = subprocess.check_output([absoluteCodePath, param])
return result
0👍
Why would you want to do that? Just import your file/module and use it, this is the correct way.
Lets say you have this code in fib.py
:
def calculate(.....):
#code. ...
return result
Now in you other file, lets say it’s views.py
just do:
import fib
# this is the search view
def search(request):
if request.method == "POST":
# other code
fib.calculate(param) # where param is the value of the search field
I’m not sure if I understood you correctly.. but no there’s no reason to use subprocess
and execute a file and get the value returned…
- [Answer]-Django form validation looks like bad code
- [Answer]-Django AbstractUsers create_user not working properly
Source:stackexchange.com