从 HTML 按钮运行 Python 脚本 [英] Running Python scripts from HTML button

查看:29
本文介绍了从 HTML 按钮运行 Python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

P 正在尝试使用 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.

我对使用 Raspberry Pi 还很陌生.

I am quite new to working with Raspberry Pis.

推荐答案

我不确定您是否可以在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆