从HTML按钮运行Python脚本 [英] Running Python scripts from HTML button
问题描述
我试图使用Lighttpd web服务器/ PHP 7.0实现一个运行Python脚本 forward.py
(使我的机器人向前移动)的按钮。
P am trying to implement a button that will run a Python script forward.py
(move my robot forward) using Lighttpd web server/PHP 7.0.
Python脚本在终端窗口中执行时效果很好,但是当我尝试从点击按钮运行它时它不起作用。
The Python script works perfectly when executed in the terminal window however when I try to run it from the click of the button it does not work.
这是执行 .py
脚本的基本HTML代码:
Here is my basic HTML code to execute the .py
script:
<html><body>
<h1> Development of Internet controlled robot </h1>
<input type="button" name="forwardbutton" value=" Move forward "onClick="<? exec(' python /var/www/html/forward.py'); ?>">
</body></html>
我已更改的所有者forward.py
脚本为 www-data
但这没有什么区别。
I have changed the owner of the forward.py
script to be www-data
however this has made no difference.
我很新树莓派。
推荐答案
我不确定你可以在onClick事件中打开php标签。
您应该调用javascript函数也许并且使用ajax(以避免刷新)调用将具有exec(python程序)函数的php页面。
I am not sure you can open php tags inside onClick event. You should call javascript function maybe and use ajax (to avoid refresh) to call the php page which will have the exec(python program) function.
看看这里用onClick执行PHP函数
这篇关于从HTML按钮运行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!