Python新手入門webpy小應用開發(fā)
web.py 是一個輕量級Python web框架,它簡單而且功能強大。
web.py 是一個Python 的web 框架,它簡單而且功能強大。web.py 是公開的,無論用于什么用途都是沒有限制的。而且相當的小巧,應當歸屬于輕量級的web 框架。
首先使用pip/pip3安裝webpy
pip install web.py
最新版0.61需要 Python >= 3.5版本0.51 需要Python 2.7這是一個入門的例子app.py
import weburls = ( ’/(.*)’, ’hello’)app = web.application(urls, globals())class hello: def GET(self, name):if not name: name = ’World’return ’Hello, ’ + name + ’!’if __name__ == '__main__': app.run()
啟動運行命令:
python3 app.py
默認端口位8080,瀏覽器訪問http://0.0.0.0:8080/
項目開始準備requirements.txt web.py==0.62 然后開始寫我們的第一個模版
#!/usr/bin/python # -*- coding:utf8 -*- import web,osurls = (’/’,’index’)render = web.template.render(’templates/’)class index: def GET(self): name = ’千年碼農’ return render.index(name)if __name__ == '__main__': app = web.application(urls,globals())app.run()
項目源代碼地址:https://gitee.com/shuogesha/py_flash
到此這篇關于Python新手入門webpy小應用開發(fā)的文章就介紹到這了,更多相關Python新手入門webpy小應用開發(fā)內容請搜索好吧啦網以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
