I am new to Django. I would like to run some command from some view. Something like:
python /path/to/the/script/run.py -id 11 --user root --run_digital_id 29 --workflow map --lib_group library.yaml --log log.conf
I use this method to call:
def run_in_background(cmd):
logging.info('running ' + cmd)
p = subprocess.Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
output, errors = p.communicate()
print output
print errors
logging.debug(output)
logging.debug(errors)
The command is passed to the method run_in_background(). When I copy the command and run on the terminal, it works well. But when I run it from some view of Django, it reports:
Traceback (most recent call last):
File "/path/to/the/script/run.py", line 11, in ?
import conf, util
File "/path/to/the/script/conf.py", line 11
class Settings():
^
SyntaxError: invalid syntax
Er, the run_in_background method is also working when I call it from some ‘plain’ python code.
The error position is the first line of my program. I suspect there is something wrong with the paths… But after searching for long time, I did not get the reason. Please help. Thanks.
Seems like this is the solution!
In some python version defining class with empty parenthesis like
class Settings():is not valid, you may want to change it toclass Settings(object):