我有一个非常简单的网页,我正在使用,以旋转步进电机上的覆盆子Pi。我的html文件是:
<html>
<head>
<script Language="Javascript">
function ccw()
{
document.location="cgi-bin/rotate_45_ccw.py";
}
function cw()
{
document.location="cgi-bin/rotate_45_cw.py";
}
</script>
</head>
<body>
<div style="text-align:center">
<h1>Raspberry Pi GPIO</h1>
<br>
<button type="button", id="ccw", onclick="ccw()", value="value CCW">Rotate CCW</button>
<button type="button", id="cw", onclick="cw()", value="value CW">Rotate CW</button>
<br>
</div>
</body>
</html>我想要做的是,在执行任何一个脚本之后,页面就会被刷新(这样用户就可以再次单击任何一个按钮)。我猜最愚蠢的方法是让Python脚本输出上面的html代码。有没有更聪明/更容易的方法?
谢谢!
发布于 2016-05-27 20:31:21
经过了大量的搜索,我终于把它做对了!因此,为了重定向到主页,我必须在我的print脚本末尾添加以下python3语句:
print ("Content-type: text/html\n\n")
print ("<html><body>\n")
print ("<meta http-equiv=\"refresh\" content=\"0; url = http://192.168.1.109\" />")
print ("</body></html>")发布于 2016-05-23 20:44:36
不,不要简单地返回页面-按下例如f5-重新加载将再次执行此操作。从python脚本返回一个带有控制页面URL的303 See Other。因此,您总是有相同的“登陆页”,而不必对相同的东西编码两次。理想情况下,旋转操作应该是http (它们并不没有副作用),但这是一个不同的主题。
https://stackoverflow.com/questions/37399965
复制相似问题