最近有一個小的web項目,想用喜愛都python,但是想到之前接觸過都django我感覺一陣不寒而栗,為什么?Django的配置太過復(fù)雜,而且小項目不太適合MVC的開發(fā)模式,所以我將目光轉(zhuǎn)向了web.py這個小型web框架,并且真正讓我動心都是其官方網(wǎng)站上都一句話:"Django lets you write web apps in Django. TurboGears lets you write web apps in TurboGears. Web.py lets you write web apps in Python." ― Adam Atlas
最近切換了Ubuntu替換了Win7系統(tǒng),所以這里介紹下Ubuntu都安裝web.py
安裝easy_install
sudo apt-get install python-pip
使用easy_install安裝web.py
sudo easy_install web.py
測試是否安裝成功:
在python shell中執(zhí)行:
import web
如果沒有報錯則web.py安裝成功. 下面開始我們第一個hello,world
import weburls = ("/.*", "hello") # 指定任何url都指向hello類app = web.application(urls, globals()) # 綁定url# 定義相應(yīng)類class hello:def GET(self):return 'Hello, world!'if __name__ == "__main__":app.run()然后保存為hello.py并運行它
python hello.py
然后會看到輸出:http://0.0.0.0:8080/
然后瀏覽器訪問:http://localhost:8080即可看到 Hello, world! 我們第一個用python寫的web程序就建立完成.
新聞熱點
疑難解答
圖片精選