Answer the question
In order to leave comments, you need to log in
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})
Answer the question
In order to leave comments, you need to log in
Use django to run a bashscript, in order to run a python script is
fine
Use django commands
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question