web.py实例--notes笔记系统

说明蓝色=命令名称python

      浅绿=命令参数mysql

      浅蓝=选项git

      紫色=目录github

      系统环境:CentOS  5.5  x86_64web

学web.py框架时写的一个很小很简陋的小实例,效果如图:sql

运行环境 python 2.6以上,mysql数据库。数据库

建库脚本:createdb.py框架

  
  
  
  
  1. #!/usr/bin/env python27  
  2. #-*- coding:utf-8 -*-  
  3. import MySQLdb,sys  
  4.  
  5. conn = MySQLdb.connect(host='localhost',user='root',passwd='')  
  6. cursor = conn.cursor()  
  7. cursor.execute("create database if not exists notes")  
  8.  
  9. conn.select_db('notes')  
  10. cursor.execute("create table if not exists notes(nid int(10) not null primary key auto_increment,date date,time time, text text  default null ,comment int(10) default 0)")  
  11. cursor.execute("create table if not exists user(uid int(5) not null primary key auto_increment,user varchar(10) not null,passwd varchar(20) not null ,perm int(2) default 1,datetime datetime)")  
  12. cursor.execute("create table if not exists comment(nid int(10) not null primary key auto_increment,cid int(10) not null,datetime datetime,name varchar(20)  default '匿名',mail varchar(20) default '保密', comment text )")  
  13. cursor.execute("insert into user(user, passwd) values('admin', password('123456'))")  
  14. cursor.execute("insert into notes(date,time,text)values(now(),now(),'hello world')")  
  15. cursor.close()  
  16. conn.close() 


 

配置脚本:setting.pyide

  
  
  
  
  1. #!/usr/bin/env python27  
  2. #-*- coding:utf-8 -*-  
  3. import web  
  4. #import sae.const  
  5.  
  6. urls = ('''reindex',   
  7.         '/','index',  
  8.         '/add','add',  
  9.         '/login','login',  
  10.         '/about','about',  
  11.         '/logout','logout',  
  12.         '/alter','alter',  
  13.         '/new''new',  
  14.         '/search','search',  
  15.         '/comment','comment' 
  16.         )  
  17. render = web.template.render("templates/")  
  18.  
  19. #db = web.database(dbn='mysql', db = sae.const.MYSQL_DB, host = sae.const.MYSQL_HOST, port = int(sae.const.MYSQL_PORT), user = sae.const.MYSQL_USER, pw = sae.const.MYSQL_PASS)  
  20. db = web.database(dbn='mysql', db='notes', host='localhost', port=3306, user='root', pw=''

根据本身状况自行定义。ui

配置好环境 运行 run.py 而后经过8080端口就能够访问了。

×××:https://github.com/zuopucuen/notes

相关文章
相关标签/搜索