我正在关注MagPi杂志的教程,网址为web.py.这是一个程序,你可以创建一个表单,然后你可以点击一个按钮,然后它做了一些事情。 (2013年2月第9期)
这是我的主要代码:
#!/home/pi/pyserver
import os
import web
from web import form
# define the pages
urls = ('/', 'index')
render = web.template.render('templates')
app = web.application(urls, globals())
# define buttons to be shown on the form
my_form = form.Form(
form.Button("btn", id="btn0", value = "0", html="One!", class_="btnZero"),
form.Button("btn", id="btn1", value = "1", html="Two!", class_="btnOne"),
form.Button("btn", id="btn2", value = "2", html="Three!", class_="btnThree")
)
# define what happens when the index page is called
class index:
# GET is used when the page is first requested
def GET(self):
form = my_form()
return render.index(form, "RPi Remote Control")
# POST is called when a web form is submitted
def POST(self):
# get the data submitted from the web form
userData = web.input()
if userData.btn == "0":
print "TEST 1"
# MORE STUFF HERE
elif userData.btn == "1":
print "TEST 2"
elif userData.btn == "2":
print "TEST 3"
else:
print "WHAT IS GOING ON?"
raise web.seeother('/')
app.run()
HTML代码:
$def with (form,title)
<!doctype html>
<html>
<head>
<title>$title</title>
<link rel="stylesheet" type="text/css" href="/static/styles.css">
</head>
<body>
<br />
<form class="form" method="post">
$:form.render
</form>
</body>
</html>
CSS代码:
.classname {
-moz-box-shadow:inset 0px 1px 0px 0px #f29c93;
-webkit-box-shadow:inset 0px 1px 0px 0px #f29c93;
box-shadow:inset 0px 1px 0px 0px #f29c93;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #fe1a00), color-stop(1, #ce0100) );
background:-moz-linear-gradient( center top, #fe1a00 5%, #ce0100 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fe1a00', endColorstr='#ce0100');
background-color:#fe1a00;
-webkit-border-top-left-radius:20px;
-moz-border-radius-topleft:20px;
border-top-left-radius:20px;
-webkit-border-top-right-radius:20px;
-moz-border-radius-topright:20px;
border-top-right-radius:20px;
-webkit-border-bottom-right-radius:20px;
-moz-border-radius-bottomright:20px;
border-bottom-right-radius:20px;
-webkit-border-bottom-left-radius:20px;
-moz-border-radius-bottomleft:20px;
border-bottom-left-radius:20px;
text-indent:0;
border:1px solid #d83526;
display:inline-block;
color:#ffffff;
font-family:Arial;
font-size:15px;
font-weight:bold;
font-style:normal;
height:50px;
line-height:50px;
width:100px;
text-decoration:none;
text-align:center;
text-shadow:1px 1px 0px #b23e35;
}
.classname:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ce0100), color-stop(1, #fe1a00) );
background:-moz-linear-gradient( center top, #ce0100 5%, #fe1a00 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ce0100', endColorstr='#fe1a00');
background-color:#ce0100;
}.classname:active {
position:relative;
top:1px;
}
/* This button was generated using CSSButtonGenerator.com */
我已经设置了所有文件,就像在教程中一样。当我运行python程序时,它打印出http://0.0.0.0:8080
,但每当我尝试通过手机连接它时(就像在教程中一样),它会出现类似This page cannot be loaded via the Chrome Data Compression Proxy. Try reloading the page
的内容。
出了什么问题?我无法连接到Web服务器。
答案 0 :(得分:0)
此问题源自iOS或Android设备中的Chrome。不是你的网络服务器,因为你说你的桌面浏览器工作正常。
这是Google Chrome数据压缩代理的link。
它必须以某种方式限制对localhost8080的访问。通过切换&#34;设置&gt;停用它带宽管理&gt;减少数据使用量#34;。
只是提示,在你提出Stack Overflow问题之前,你应该 Google 。