[1] Tornado Todo Day0

Github地址: day0css

初始化數據庫:

jakeychen@JC:~/Public/tornado_todo$ pwd
/home/jakeychen/Public/tornado_todo
jakeychen@JC:~/Public/tornado_todo$ mysql -u root -p < todo.sql 

輸入密碼 Aa123456 (假設你設置的密碼爲這個),完成mysql的初始化。html

運行程序:

jakeychen@JC:~/Public/tornado_todo$ python srv.py 

在瀏覽器(Chrome)查看運行效果:

嘗試新增幾個todo看一下效果:

標記爲完成:

這樣一個簡單的待辦事項就運行起來了python

 

目前的項目大體結構:

tornado_todo/
├── application.py
├── conf
│   ├── config.yaml
│   └── logging.yaml
├── handlers
│   ├── base.py
│   ├── delete.py
│   ├── edit.py
│   ├── finish.py
│   ├── index.py
│   ├── __init__.py
│   └── new.py
├── logs
│   ├── all.log
│   ├── ingenia.log
│   └── warn.log
├── README.md
├── srv.py
├── static
│   ├── css
│   │   ├── app.css
│   │   └── normalize.css
│   ├── images
│   │   ├── favicon.ico
│   │   ├── ok.gif
│   │   └── tornado.png
│   └── js
├── templates
│   ├── base.html
│   ├── edit.html
│   └── index.html
├── todo.sql
└── url.py

1. application.py 一些配置設置mysql

 1 # coding:utf-8
 2 
 3 import os
 4 import uuid
 5 import base64
 6 
 7 import tornado.web
 8 
 9 settings = dict(
10     template_path=os.path.join(os.path.dirname(__file__), "templates"),
11     static_path=os.path.join(os.path.dirname(__file__), "static"),
12     xsrf_cookies=True,
13     cookie_secret=base64.b64encode(uuid.uuid4().bytes+uuid.uuid4().bytes),
14     login_url="/login",
15     debug=True,
16 )
View Code

2. url.py 記錄URL和映射的類jquery

 1 # coding:utf-8
 2 
 3 
 4 url = [(r"^/", "handlers.index.IndexHandler")]
 5 
 6 url += [(r"^/todo/new", "handlers.new.NewHandler")]
 7 
 8 url += [(r"^/todo/(\d+)/edit", "handlers.edit.EditHandler")]
 9 
10 url += [(r"^/todo/(\d+)/delete", "handlers.delete.DeleteHandler")]
11 
12 url += [(r"^/todo/(\d+)/finish", "handlers.finish.FinishHandler")]
View Code

3. todo.sql 初始化mysqlgit

 1 # $  mysql -u root -p < mysql_create.sql 
 2 # Aa123456
 3 
 4 drop database if exists tornado_todo;
 5 
 6 create database tornado_todo;
 7 
 8 GRANT ALL ON tornado_todo.* TO 'tornado' IDENTIFIED BY '123';
 9 
10 use tornado_todo;
11 
12 create table todo (
13     `id` mediumint not null auto_increment,
14     `todo_text` varchar(50) not null,
15     `finished` bool not null default 0,
16     `post_date` datetime not null default now(),
17     primary key (`id`)
18  ) engine=innodb default charset=utf8;
View Code

4. handlers/ 請求的各個類github

5. static/ 靜態文件web

6. templates/ html文件sql

7. conf/ 配置文件數據庫

8. logs/ 存放log文件

 

Todo:

1. 使用jquery,分離出全部的css和js。

2. 使用sqlalchemy改寫數據庫操做。

相關文章
相關標籤/搜索