[Django]-Running Python file from Django views

3👍

As you’re trying to run python script, you may simply import code from launch_instances.py into your view, redirect output to /home/bitnami/launcinstances.log (about redirecting stdout to file in python: Redirect stdout to a file in Python?). But there’s still problem with root privileges – one option is to change permissions of: resources needed for calling code from launch_instances.py; your log file; to allow your django process to execute that, second option (not recommended) is to run django app as root.

👤Marek

3👍

Most likely it has something to do with permissions. Try examining stderr and stdout of your command execution. I’m using this code to debug my shell commands:

process = subprocess.Popen(shlex.split(command), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output,error = process.communicate(input=pipe)

Leave a comment