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