代码地址:https://code.youkuaiyun.com/ranky2009/pythonsmallproject
Python版本:3.4.3
操作系统:win7此项目是分析python基础教程(第二版)的项目7:自定义公告板。改为适合于win7和python3的版本。
运用cgi,在项目六中有介绍。
准备工作:
1. 安装Mysql
http://blog.youkuaiyun.com/ranky2009/article/details/46885393
2. 在python中连接Mysql
http://blog.youkuaiyun.com/ranky2009/article/details/46900677
3. 创建数据库以及表
create database MyBoard;
use MyBoard;
create table messages(
id INT NOT NULL AUTO_INCREMENT,
subject VARCHAR(100) NOT NULL,
sender VARCHAR(15) NOT NULL,
reply_to INT,
text MEDIUMTEXT NOT NULL,
PRIMARY KEY(id)
);
4. 添加数据到数据库
insert into messages values(1, 're: first email', 'li xiao', 2, 'good job, multi-text');
insert into messages values(null, 'first email', 'lucy', null, 'learn python for fun');
insert into messages values(null, 'test email', 'lily', null, 'just test email');
insert into messages values(null, 're: re: first email ', ' lucy ', 1, 'just test email');
项目代码:
1. main.cgi