盒子
盒子
文章目录
  1. 安装
  2. hello world
  3. 常规用法
  4. 数据库

web.py

安装

pip install web.py

hello world

  • 端口: 默认8080, 可以通过命令行修改 python test.py 8081
  • 发现HTTP请求时,创建新进程,所以脚本更新,即时生效
# Hello world
import web

urls = ("/.*", "hello") # 与类名相对应,大小写敏感
app = web.application(urls, globals())

class hello:
def GET(self):
return 'Hello, world!'

if __name__ == "__main__":
app.run()

常规用法

class hello:
def GET(self):
data = web.input() # URL上报所有参数,包含post,get,表单
return 'Hello, world!'

数据库

db = web.database(
dbn='mysql', host='localhost', port=3306,
db='test_db', user='test', passwd='123456')

data = db.select("test_table")
for d in data:
print(d['name'])
支持一下
扫一扫,支持一下
  • 微信扫一扫
  • 支付宝扫一扫