Python学习笔记之初识webpy

1.python 2.7版本(建议先学2.7的版本)

2.去官网下载Python msi版的直接安装

链接:https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi

配置环境变量在Path中添加D:\Python;D:\Python\Scripts;对应你安装python的路径


3.查询安装的服务:pip list


4.安装服务命令:pip install web.py


5.进入http://webpy.org/官网  
hello world例子测试 新建hello.py保存官网copy下来的代码,下面是官网的代码:
import web     
urls = (
    '/(.*)', 'hello'
)

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

class hello:        
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'
#return open (r'test.html','r').read()
if __name__ == "__main__":
    app.run()

6.运行python hello.py进行测试,localhost:8080或者localhost:8080\python.web

7.测试显示的内容其实是return返回的内容,可以直接读取一个html文件,

读取的文件是与你存放测试的python.py同一文件夹下return open (r'test.html','r').read()  

请求头:web.input
请求头获取:web.ctx.env
模板文件读取:render.index("参数")
结果数据获取:model.select("sql")

url跳转:web.seeother("/")

一个微博的例子web.py
链接:http://pan.baidu.com/s/1miv9AVA 密码:vzcf

发布了17 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Tolove_dream/article/details/75094079