|版权声明:本文为博主原创文章,未经博主允许不得转载。

首先明确我们要建一个什么样的站,作为教程(也算自己使用tornado的一个小总结),自然功能不能太多,但又满足一个普通网站需要的就行了。

目前想到的功能有:登录,注册,发表文章,删除文章,发表评论,个人主页,代码展示和个人计划管理。

数据库规范↓

#数据库规范
codedb:codes               //本地代码文件
	_id			 ID
	title			标题
	path			路径
	codetype		语言

Ps: static\codes\*.txt

codedb:blogs
	_id 		        ID
	author 		     作者
	title		        题目
	content		     内容
	datetime	        时间

codedb:users
	_id 		        ID
	username 	     用户名
	password     	     密码
	nickname	        昵称
        roleid                 权限声明

codedb:usercode
	_id			ID
	title 		        标题
	author		     作者
	codetype	        语言
	content		     代码        

main.py↓

 import os.path
 import pymongo
 from tornado import httpserver,options,web,ioloop

 from tornado.options import define,options
 define('port',default=8000,help=None,type=int)

 class Application(web.Application):
     def __init__(self):
         handlers = [(r'/',IndexHandler),
         (r'/sign/(\w+)',SignHandler),
         (r'/code/(\w+)',CodeHandler),
         (r'/user/(\w+)',UserHandler),
         (r'/blog/(\w+)',BlogHandler)]
         settings = dict(template_path=os.path.join(os.path.dirname(__file__), "templates"),
         static_path=os.path.join(os.path.dirname(__file__), "static"),
         debug=True)
         conn = pymongo.MongoClient('localhost',27017)
         self.db = conn.codedb
         web.Application.__init__(self,handlers,**settings)

 options.parse_command_line()
 http_server = httpserver.HTTPServer(Application())
 http_server.listen(options.port)
 ioloop.IOLoop.instance().start()

代码的理解参考Tornado文档翻译1.2.1部分

/ →主页
/sign →登录注册退出等操作
/code →代码部分
/user →用户登录以后的操作
/blog →与文章有关的操作

然后就可以在templates目录下创建相应的html文件

main.html
index.html
sign/
    signup.html
    signin.html
code/
    codelist.html
    codeview.html
    codeadd.html
/user
    usercen.html
    userblog.html
    userinfo.html
/blog
    bloglist.html
    blogview.html

main.html就是网站其它页面的父模块,里面主要是网页总体框架↓

  <!DOCTYPE html>
  <html lang="en">
  <head>
      <meta charset="UTF-8">
      <title>学习小站|TSSS|CODE</title>
      <link rel="stylesheet" href="{{ static_url("css/bootstrap.min.css") }}">
      <link rel="stylesheet" href="{{ static_url("css/bootstrap-theme.css") }}">
      <script type="text/javascript" src="{{ static_url("js/bootstrap.min.js") }}"></script>
      <script type="text/javascript" src="{{ static_url("js/jquery-1.11.1.js") }}"></script>
      <script type="text/javascript" src="{{ static_url("js/tinymce/tinymce.js") }}"></script>
      <script>tinymce.init({ selector:'textarea' });</script>
      <script type="text/javascript" src="{{ static_url(r"js/syntaxhighlighter/scripts/shCore.js") }}"></script>
      <script type="text/javascript" src="{{ static_url(r"js/syntaxhighlighter/scripts/shBrushCpp.js") }}"></script>
      <link type="text/css" rel="stylesheet" href="{{ static_url(r"js/syntaxhighlighter/styles/shCoreDefault.css") }}"/>
      <script type="text/javascript">SyntaxHighlighter.all();</script>
  </head>
  <body>
  <div class="container">
      <div class="row clearfix">
          <div class="col-md-12 column">
              <div class="page-header">
                  <h1>
                      学习小站 <small>Small Study Station</small>
                  </h1>
              </div>
              {% block content %}
              {% end %}
          </div>
      </div>
  </div>
  <script type="text/javascript" src="{{ static_url("js/bootstrap.min.js") }}"></script>
  <script type="text/javascript" src="{{ static_url("js/jquery-1.11.1.js") }}"></script>
  </body>
 3</html>

这样总体结构和网页的布局就大概像个样子了。

--Part.One--

最新文章

  1. C语言 第五章 循环结构
  2. MVC利用URLRoute实现伪静态
  3. Moon.Orm 5.0其他额外配置的讲解
  4. 为nginx增加nginx_http_concat模块
  5. matlab 画框(三) 画框并保存图像
  6. MVC神韵---你想在哪解脱!(十八)
  7. Extjs4.2 多选下拉框
  8. PHP代码为什么不能直接保存HTML文件——&amp;gt;PHP生成静态页面教程
  9. 前端开发工具(安装及常用技巧)——sublime text 3
  10. 基于visual Studio2013解决C语言竞赛题之1037数组求列和
  11. Myeclipse新建 配置Hibernate
  12. MyBatis学习-SQL 符号篇
  13. Google调试工具
  14. Linux 虚拟机安装后的配置和一些命令符笔记
  15. ruby:TypeError: 对象不支持此属性或方法
  16. [Swift]LeetCode1001. 网格照明 | Grid Illumination
  17. 角度&amp;弧度转换
  18. MySQL 遇到错误集锦
  19. Git和SourceTree入门教程
  20. Centos 7 安装 PostgreSQL PGAdmin4

热门文章

  1. Android studio 签名使用转
  2. 总结新系统部署时,Oracle的一些注意事项:
  3. JavaScript声明全局变量的三种方式
  4. jquery中prop()方法和attr()方法的区别浅析
  5. Maya 2015 中英文切换
  6. Java web MVC开发模式入门感悟
  7. hdu Tempter of the Bone
  8. Python开发问题和解决方案汇集
  9. ORACLE常见错误代码的分析与解决
  10. Ajax 无刷新上传文件插件 uploadify 的使用