web.py – 网页跳转

来源:互联网 发布:spring boot sql脚本 编辑:程序博客网 时间:2024/06/05 06:11


代码实现:

import web

 

urls = ("/", "hello",

       "/test.*","testn",

       "/input1/(.+)/(.+)","input_test1",

       "/ainput","input_test2"

)

app = web.application(urls, globals())

 

class hello:

    def GET(self):

        return"hello"

 

class testn:

    def GET(self):

        raiseweb.seeother('/input1/123/456')

        #raiseweb.redirect('/input1/123/456')

         raiseweb.seeother('http://www.baidu.com')  如果带http开头,就会直接跳转网址,而不是在本网站追加。

class input_test1:

    defGET(self,name1,name2):

        return"Listing info about user: %s , %s "% (name1,name2)

 

class input_test2:

    def GET(self):

        i =web.input()

       print(i.items())

        j=i.items()

        return("Listing info about %s:%s,%s:%s" %(str(j[0][0]),str(j[0][1]),str(j[1][0]),str(j[1][1])))

 

 

if __name__ == "__main__":

    app.run()

测试结果:

输入:http://128.224.162.225:8080/test1

最后网页会打开http://128.224.162.225:8080/input1/123/456

显示: 123 , 456

 

0 0