使用CGI Python脚本刷新网页 [英] Refresh web page using a CGI Python script
问题描述
我有一个非常简单的网页,该网页用于在Raspberry Pi上旋转步进电机。我的html文件是这样的:
I have a very simple web page which I'm using in order to rotate a stepper motor on Raspberry Pi. My html file is this:
<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代码。有没有更聪明/更简便的方法?
What I want to do is after either of the scripts is executed, for the page to be refreshed (so that the user can click again on either button). The dumb way I guess, is for the Python scripts to output the above html code. Is there a smarter/easier way?
谢谢!
推荐答案
经过大量搜索后,我终于明白了!因此,为了重定向到主页,我必须在python3脚本的末尾添加以下 print
语句:
After a LOT of searching around I finally got it right! So, in order to be redirected to the home page, I have to add the following print
statements at the end of my python3 script:
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>")
这篇关于使用CGI Python脚本刷新网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!