S
S
stayHARD2016-01-21 11:59:10
Django
stayHARD, 2016-01-21 11:59:10

Running .sh script via Django view?

Hello.
I want to run a .sh script, the most common:
test.sh
echo "some data for the file" >> 0.txt
In Django I use DRF (Django REST Framework), the script needs to be run through subprocess at the moment when the POST request arrives:
views.py

@api_view(["POST"])
def start_script(request):
    if request.method == "POST":
        a = subprocess.call(['/home/ubuntu/scripts/test.sh'], shell=True)
        return Response({"status": a})

When running normally through python, the console returns 0 and everything works out as it should.
When sending a POST to a view, it returns 1 and the script does not work.
Tried through Popen, also does not work.
How can I find out what my problem is?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-01-21
@sim3x

Use django to run a bashscript, in order to run a python script is
fine
Use django commands

V
Vladimir, 2016-01-21
@vintello

why call a python application from the console from a python application?
Why can't you just call it in code?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question