zoukankan      html  css  js  c++  java
  • [1] Tornado Todo Day0

    Github地址: day0

    初始化数据库:

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

    输入密码 Aa123456 (假设你设置的密码为这个),完成mysql的初始化。

    运行程序:

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

    在浏览器(Chrome)查看运行效果:

    尝试新增几个todo看一下效果:

    标记为完成:

    这样一个简单的待办事项就运行起来了

    目前的项目大致结构:

    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 一些配置设置

     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和映射的类

     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 初始化mysql

     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/ 请求的各个类

    5. static/ 静态文件

    6. templates/ html文件

    7. conf/ 配置文件

    8. logs/ 存放log文件

    Todo:

    1. 使用jquery,分离出所有的css和js。

    2. 使用sqlalchemy改写数据库操作。

     

  • 相关阅读:
    canvas-color的几种设置
    canvas-2lineCap.html
    canvas-2lineJoin.html
    canvas-0trasform.html
    总体、个体和简单随机样本
    大数定律
    切比雪夫不等式
    B1032. 挖掘机技术哪家强
    Array(数组)对象-->join() 方法
    Array(数组)对象-->shift() 方法
  • 原文地址:https://www.cnblogs.com/jakeyChen/p/5343788.html
Copyright © 2011-2022 走看看