当前位置: 首页 > news >正文

Python web 框架web.py「简约美」

web.py is a web framework for Python that is as simple as it is powerful. web.py is in the public domain, you can use it for whatever purpose with absolutely no restrictions.

web.py 是一个简单而强大的 Python Web 框架。web.py 属于公共领域,您可以将其用于任何目的,绝对没有任何限制。

Web.py github 地址:GitHub - webpy/webpy: web.py is a web framework for python that is as simple as it is powerful.        https://pypi.python.org/pypi/web.py

Web.py Cookbook 简体中文版:http://webpy.org/cookbook/index.zh-cn

web.py 0.3 新手指南:http://webpy.org/docs/0.3/tutorial.zh-cn

webpy 官网文档:http://webpy.org/

SQLite 

#coding:utf8
import webdb = web.database(dbn='sqlite', db='MovieSite.db')
render = web.template.render('templates/')urls = ('/', 'index','/movie/(.*)', 'movie','/cast/(.*)', 'cast','/director/(.*)', 'director',
)class index:def GET(self):movies = db.select('movie')count = db.query('SELECT COUNT(*) AS COUNT FROM movie')[0]['COUNT']return render.index(movies, count, None)def POST(self):data = web.input()condition = r'TITLE LIKE "%' + data.title + r'%"'movies = db.select('movie', where=condition)count = db.query('SELECT COUNT(*) AS COUNT FROM movie WHERE ' + condition)[0]['COUNT']return render.index(movies, count, data.title)class movie:def GET(self, movie_id):movie = db.select('movie', where='id=$int(movie_id)', vars=locals())[0]return render.movie(movie)class cast:def GET(self, cast_name):condition = r'CASTS LIKE "%' + cast_name + r'%"'movies = db.select('movie', where=condition)count = db.query('SELECT COUNT(*) AS COUNT FROM movie WHERE ' + condition)[0]['COUNT']return render.index(movies, count, cast_name)class director:def GET(self, director_name):condition = r'DIRECTORS LIKE "%' + director_name + r'%"'movies = db.select('movie', where=condition)count = db.query('SELECT COUNT(*) AS COUNT FROM movie WHERE ' + condition)[0]['COUNT']return render.index(movies, count, director_name)if __name__ == "__main__":app = web.application(urls, globals())app.run()

MYSQL

import web,json,sysurls=('(/|/index.html)','index','/wyw/dbQuery','dbQuery','/wyw/upload', 'upload','/(.*?)','normal'
)
#获取第二个参数为数据库名称(第一个参数为服务器端口号)
dbname=sys.argv[2] 
if dbname=="": dbname="users"db=web.database(dbn='mysql',host="localhost",port=3306,db=dbname,user='root',pw="admin")#上传文件
class upload:def POST(self):x = web.input(myfile={})f=open('static/upload/'+x['myfile'].filename,'wb')f.write(x['myfile'].value)return json.dumps({"state":"OK"})
#一般文件获取
class normal:def GET(self,arg1):f=open('static/'+arg1,'rb')return f.read() 
#首页获取
class index:def GET(self,arg1):f=open('static/index.html','rb')return f.read()
#数据库查询、添加、修改、删除,通常数据库操作都使用这个
class dbQuery:def GET(self):data=web.input()try:if(data.sql.find('select')==0):results=db.query(data.sql)lis=[]for item in results: lis.append(item)return json.dumps({"msg":"success","rows":lis})else:return json.dumps({"msg":"success","rows":db.query(data.sql)})except Exception as e:return json.dumps({"msg":str(e)})if __name__=="__main__":app=web.application(urls,globals())  app.run()

 引用:

简单而直接的Python web 框架:web.py_import web_strivinging的博客-CSDN博客

 web.py 十分钟创建简易博客:http://blog.csdn.net/freeking101/article/details/53020728

一个简单的web.py论坛:一个简单的web.py论坛 - RussellLuo - 博客园

http://www.lryc.cn/news/165801.html

相关文章:

  • Bootstrap 重新数据查询时页码为当前页问题
  • scratch舞蹈比赛 2023年5月中国电子学会图形化编程 少儿编程 scratch编程等级考试四级真题和答案解析
  • windows下安装redis扩展库
  • 大数据平台数据安全具体措施有哪些?有推荐的吗?
  • 基于SSM的健康综合咨询问诊平台设计与实现
  • 每日一题 2596. 检查骑士巡视方案
  • 第二章 进程与线程 三、进程控制
  • 【云原生进阶之PaaS中间件】第二章Zookeeper-3.2架构详解
  • K8S:kubectl陈述式、声明式资源管理及金丝雀部署
  • docker容器日志管理
  • Oracel ORA-22992 错误的解决方法
  • CrossOver 23 正式发布:可在 Mac 上运行部分 DX12 游戏
  • 一、Mediasoup源码介绍
  • ⑧ 嵌套路由配置
  • 【ppt技巧】将幻灯片里的图片背景设置为透明
  • rrweb入门
  • OSCP系列靶场-Esay-Vegeta1保姆级
  • AJAX学习笔记9 搜索联想自动补全
  • Docker启动失败报错Failed to start Docker Application Container Engine解决方案
  • 安装React脚手架
  • 想要精通算法和SQL的成长之路 - 受限条件下可到达节点的数目
  • 加快项目开发进度常用5种方法
  • leetcode做题笔记136. 只出现一次的数字
  • vuex 模拟异步调用
  • error:Failed building wheel for XXX
  • 【linux命令讲解大全】112.Linux 系统管理工具:dpkg-statoverride 和 dstat 的使用介绍
  • ffmpeg草稿
  • 熵 | 无线通信知识
  • 黑马JVM总结(七)
  • Vue3核心语法一