开源地址

https://github.com/gongqingkui/webFrameBaseOnWeb.py

sqlite3数据库如下

PRAGMA foreign_keys=OFF;

BEGIN TRANSACTION;
CREATE TABLE msgs(id integer primary key,name text,date text,content text);
INSERT INTO "msgs" VALUES(3,'王五','2016-05-20 15:49:59','我叫王五,是一个路人甲,有天我在街上走着,看到对面来了一个人。这个人膀大腰圆,身上纹着一条龙……');
INSERT INTO "msgs" VALUES(4,'GONG QingKui','2016-05-20 16:09:12','This is a simple webframe base on web.py.
');
COMMIT;

代码如下
# encoding: utf-8
import web,os,sqlite3,time
from web import form
#templete floder
render = web.template.render('templates/')
#url tables
urls = ('/', 'viewPost',
    '/newPost', 'newPost',
    '/new', 'new',
    '/delete','delete',
    '/editPost', 'editPost',
    '/edit', 'edit',
    '/viewPost', 'viewPost')

#get or post -> function
class delete:
    #GET function
    def GET(self):
        # url eg. http://192.168.1.3:1234/delete?id=1
        i = web.input(id=None)
        #db
        sdb = sqldb()
        sdb.cu.execute('delete from msgs where id = ?', i.id)
        sdb.conn.commit()
        #go to /viewPost page
        return web.seeother('/viewPost')

class edit:
    #POST function
    def POST(self):
        #the form is i
        i = web.input()
        date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        sdb = sqldb()
        i = (i.name, i.content, i.id)
        rec = sdb.cu.execute(
            'update msgs set name = ?,content= ? where id = ?', i)
        sdb.conn.commit()
        return web.seeother('/viewPost')

def GET(self):
        return web.seeother('/')

class new:
    def POST(self):
        i = web.input()
        date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        sdb = sqldb()
        rec = sdb.cu.execute('select * from msgs')
        dbre = sdb.cu.fetchall()
        for k in dbre:
            j = k[0] + 1

t = (j, i.name, date, i.content)
        print t
        sdb.cu.execute('insert into msgs values(?,?,?,?)', t)
        sdb.conn.commit()
        return web.seeother('/viewPost')

def GET(self):
        return web.seeother('/')

class newPost:
    def GET(self):
        return render.newPost()

class editPost:
    def GET(self):
        i = web.input()
        sdb = sqldb()
        rec = sdb.cu.execute('select * from msgs where id = ?', i.id)
        dbre = sdb.cu.fetchall()
        return render.editPost(dbre)

class viewPost:
    def GET(self):
        sdb = sqldb()
        rec = sdb.cu.execute('select * from msgs')
        dbre = sdb.cu.fetchall()
        return render.viewPost(dbre)

class sqldb:
    def __init__(self):
        if os.path.exists('msg.db'):
            self.conn = sqlite3.connect('msg.db')
            self.cu = self.conn.cursor()
        else:
            self.conn = sqlite3.connect('msg.db')
            self.cu = self.conn.cursor()
            self.cu.execute('create table msgs(id integer primary key,name text,date text,content text)')
            self.cu.execute("insert into msgs values(1,'gong','2016-05-16 16:36:00','hello gong')")
            self.conn.commit()

if __name__ == '__main__':
    app = web.application(urls, globals())
    app.run()

A simple webframe base on web.py相关推荐

  1. Python——web.py模块错误【UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xab in position 285】解决方案

    问题描述 render = web.template.render('templates', base='base') During handling of the above exception, ...

  2. web.py 十分钟创建简易博客

    From:http://blog.csdn.net/caleng/article/details/5712850 一.web.py简介 web.py 是一款轻量级的 Python web开发框架,简单 ...

  3. web.py开发web 第一章 Hello World

    2019独角兽企业重金招聘Python工程师标准>>> 前言   这一系列的文章主要针对使用web.py+jinja2+sqlalchemy+formalchemy+jquery+k ...

  4. Python轻量级WEB框架web.py,模板使用

    首先是安装web.py,方法有几种,如下 pip install web.py==0.40 easy_install web.py 或者是下载http://webpy.org/install.zh-c ...

  5. 简单而直接的Python web 框架:web.py

    From:https://www.oschina.net/question/5189_4306 Web.py github 地址:https://github.com/webpy/webpy      ...

  6. python 实现网站_python 实现网站_用web.py实现python网站版hello world网页

    github源码安装 浏览器打开https://github.com/webpy/webpy,下载源码zip格式,解压出来.cmd打开,cd到解压目录,输入 python setup.py insta ...

  7. web.py使用要点

    这几天有一个构建restful services的需求,我采用了web.py,之前并没有使用过,但在使用中确实给我带来了很多惊喜.当然,最大的惊喜就是简单,方便.之前开发restful服务的时候,采用 ...

  8. web.py做图片上传网页

    简单而直接的Python web 框架:web.py 网页界面属于前端,可以用html HTML5 上传图片文件(含拖拽.预览.上传.美化) HTML 入门笔记 - 初识HTML 如何实现一个简易的图 ...

  9. web.py搭建服务器

    python搭建服务器 ------------------安装web.py------------------------ Windows10 python3.5 安装web.py问题    pip ...

最新文章

  1. BigDecimal 比较大小需要注意的事项
  2. Android移动开发之【Android实战项目】DAY14-修改json里某个字段的值
  3. ASM模型对人脸特征点的检测
  4. 海蜘蛛路由弹窗广告破解
  5. AndroidStudio gradle配置
  6. 【PowerBi】Power Query 对数据进行合并查询
  7. boost::hana::make_range用法的测试程序
  8. 微软NNI---AutoFeatureENG
  9. [topcoder]AvoidRoads
  10. 常见的几种网络抓包及协议分析工具
  11. soundpool android,Android中用SoundPool播放音频
  12. Cors跨域(三):Access-Control-Allow-Origin多域名?
  13. 实验:4级流水线32bits全加器
  14. RK356X系列(RK3568)GL857L芯片 USB驱动开发
  15. python文件是什么的集合和抽象_python学习笔记(三):文件操作和集合
  16. 控制输入框弹出弹窗 和不弹出窗口
  17. Ubuntu Linux开机黑屏的永久解决办法
  18. C语言变量常量和标识符
  19. 手把手实现MATLAB的CNN回归
  20. WPCSYS ansys命令

热门文章

  1. 【重学UML】UML类图关系及其对应代码
  2. ubuntu16怎么升级到ubuntu18
  3. js 页面跳转两种方式(原页面跳转,打开新标签页)
  4. 生僻字怎么用计算机的,最实用生僻字输入方案大全
  5. SSH学习(个人笔记)
  6. linux怎么做bt种子文件,linux 制作BT种子并获取BT种子信息
  7. Windows 10的TPM模块到底是不是美国全球监控体系的奠基石?
  8. 2014年实习生招聘之武汉光庭信息技术有限公司实习生招聘部分笔试题(Java)—2014/04/14
  9. 海明校验码简析与举例
  10. Android两种时间轴实现