【问题标题】:web.py can't access website?web.py 无法访问网站?
【发布时间】:2014-05-14 08:27:06
【问题描述】:

我正在学习 MagPi 杂志的教程,其中包含 web.py。这是一个程序,您可以在其中创建一个表单,然后您可以单击一个按钮,然后它会执行某些操作。 (第 9 期,2013 年 2 月)

这是我的主要代码:

#!/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 的东西。

出了什么问题?我无法连接到网络服务器。

【问题讨论】:

    标签: python web.py


    【解决方案1】:

    此问题是由您 iOS 或 Android 设备中的 Chrome 引起的。不是你的网络服务器,因为你说它在你的桌面浏览器上运行良好。

    这是 Google Chrome 数据压缩代理的 link

    它必须以某种方式限制对 localhost8080 的访问。通过切换“设置 > 带宽管理 > 减少数据使用”来禁用它。

    只是提示,您应该在 Stack Overflow 中提问之前Google

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-10
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多