0

I am making an API for an android app. As soon as the input is given to the API, I need the API to execute a python file for me which is in my computer. I'm thinking of using my computer as a server on trial basis. I hope you are able to understand my question. Please let me know on how to run a python file from the API

1 Answer 1

3

You can have a view that when someone visits the url it will launch another process:

from django.http import HttpResponse
from django.views.generic import View
import subprocess

class ExecutePythonFileView(View):
    def get(self, request):
        # Execute script
        subprocess.call(['python', 'somescript.py'])

        # Return response
        return HttpResponse("Executed!")
Sign up to request clarification or add additional context in comments.

1 Comment

@ShraveenB.S If you find the answer helpful please mark it as correct answer, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.