【发布时间】:2020-02-29 05:47:41
【问题描述】:
我正在为 Android 应用程序制作 API。只要将输入提供给 API,我就需要 API 为我执行计算机中的 python 文件。我正在考虑将我的计算机用作试用服务器。我希望你能理解我的问题。请告诉我如何从 API 运行 python 文件
【问题讨论】:
标签: python django rest api django-rest-framework
我正在为 Android 应用程序制作 API。只要将输入提供给 API,我就需要 API 为我执行计算机中的 python 文件。我正在考虑将我的计算机用作试用服务器。我希望你能理解我的问题。请告诉我如何从 API 运行 python 文件
【问题讨论】:
标签: python django rest api django-rest-framework
您可以看到当有人访问该 url 时,它将启动另一个进程:
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!")
【讨论】: