微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 web.py

如何解决使用 web.py

我有 2 页。索引和索引2。我不确定如何提供 web.py 2 GET 函数或强制 python 显示 1 页,然后重定向。 它们都只是在运行并连接到本地。

方法

我在下面的示例中尝试只渲染,但除非我返回它,否则 render.index() 什么也不做。

render = web.template.render('templates/')
urls = (
  '/','index','index2'
)

class index:
    def GET(self):
        render.index()   ### this first render does nothing

        return render.index2()

if __name__ == "__main__":
    app = web.application(urls,globals())
    app.run()

这个方法不显示一个索引

方法 2

2 个独立的服务器,第一个显示索引 1,索引 1 有一些 javascript 将其重定向到第二页。 (maina.py 显示 index1 并在端口 7777 上运行,还有 mainb.py 显示 index2 并在 7778 上运行)尝试重定向到第二页时,此方法会引发错误

index1.html javascript

<script type="text/javascript">window.location.href = "127.0.0.1:7778";  </script>

main.py

render = web.template.render('1/')
urls = (
  '/','index2'
)
class index:
    def GET(self):
        return render.index()   
if __name__ == "__main__":
    app = web.application(urls,globals())
    app.run()

mainb.py

render = web.template.render('1/')
urls = (
  '/','index2'
)
class index2:
    def GET(self):
        return render.index2()   
if __name__ == "__main__":
    app = web.application(urls,globals())
    app.run()

错误如下。

错误

for pat,what in mapping:
    ValueError: not enough values to unpack (expected 2,got 1)

(ps。我的索引都不需要变量,即我没有使用模板,它只是一个普通的 html)

如何让 python 渲染 1 个页面,然后再渲染另一个页面

编辑:这真的不可能吗?我一直在四处打听,但没有得到直接的答案。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。