[英]How to run a python file in command promt when a button is clicked is on a webpage
I am trying to make a local webpage which later on will be deployed, in which when a button on the html webpage is clicked, it opens up a commend prompt window and run the program.我正在尝试制作一个稍后将部署的本地网页,其中当单击 html 网页上的按钮时,它会打开一个推荐提示 window 并运行程序。 I have tried to implement it this using django framework.
我尝试使用 django 框架来实现它。 I have added the python file to the project library for it to be accessible, I have implemented it in the following way in views.py file,
我已将 python 文件添加到项目库中以使其可访问,我已在 views.py 文件中以以下方式实现它,
def beast(request):
out = run(sys.executable, ['beast.py'], shell=True)
return render(request,'page2.html')
No input is to be given to the python file.不向 python 文件提供任何输入。 It compiles and runs, but when the button is clicked it gives out a
TypeError - bufsize must be an integer
它编译并运行,但是当单击按钮时,它会发出
TypeError - bufsize must be an integer
Please let me know what can be done for it to work请让我知道可以做些什么来让它工作
I think you have to define a function inside the beast.py which contains the code you have to run like this我认为您必须在 beast.py 中定义一个 function ,其中包含您必须像这样运行的代码
beast.py野兽.py
def beast_func():
//your code....
...............
and import that function in views.py并在views.py中导入function
from .beast import beast_func
then call the function然后调用 function
def beast_view(request):
beast_func()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.