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

首先明确我们要建一个什么样的站,作为教程(也算自己使用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--

Python快速建站系列-Part.Two-结构化和布局的更多相关文章

  1. Python快速建站系列-Part.One-组装开发环境

    |版权声明:本文为博主原创文章,未经博主允许不得转载. 源代码都在github上:SmallStudyStation 现在是个demo,但回来会租个服务器,等功能完善了放到服务器上挂着,域名jusot ...

  2. Python快速建站系列-Part.Three-注册和登录

    |版权声明:本文为博主原创文章,未经博主允许不得转载. 上一个Part已经给TSSS编好了一个简单的Web服务,网页的基础模版也写好了,那从这个Part开始就慢慢增加编写功能. 先写基础功能:注册和登 ...

  3. Python快速建站系列-Part.Six-文章内容浏览

    |版权声明:本文为博主原创文章,未经博主允许不得转载. 其实到这里网站的基本功能已经完成一半了,第六节就完成文章内容的阅读功能. 完成blogview.html↓ {% extends "m ...

  4. Python快速建站系列-Part.Five.3-个人主页及资料页面

    |版权声明:本文为博主原创文章,未经博主允许不得转载. 第五部分最后一节,完成个人主页里资料页面的个人资料的展示和修改功能,不过毕竟功能比较少,个人资料其实只有昵称一项,手动滑稽. 一如既往先写出来u ...

  5. Python快速建站系列-Part.Five.2-个人主页及文章列表

    |版权声明:本文为博主原创文章,未经博主允许不得转载. 从usercen.html就可以发现我为个人主页设了三个分开的小版面:写文章.个人文章目录.个人资料 所以按顺序Part.Five的第二部分就完 ...

  6. Python快速建站系列-Part.Five.1-个人主页及发表文章

    |版权声明:本文为博主原创文章,未经博主允许不得转载. 现在的TSSS已经有了注册和登录的功能,首页的内容也填充好了,那这一节就完成用户个人主页的内容和发表文章功能的实现. 先完成用户个人主页的use ...

  7. Python快速建站系列-Part.Four-首页内容填充

    |版权声明:本文为博主原创文章,未经博主允许不得转载. Part.Three中实现了注册和登录的功能,那这一节完成主页内容的填充,并且主页中要实现简单的可以查找代码的功能. 而且有于公共代码部分存储在 ...

  8. PHPCMS快速建站系列之搜索功能

    默认模板的搜索功能代码 <div class="bd"> <form action="{APP_PATH}index.php" method= ...

  9. PHPCMS快速建站系列之自定义分页函数

    内容分页的实现方法:{pc:content action="lists" catid="$catid" order="id DESC" nu ...

随机推荐

  1. 转载 Android快捷键 转载

    一.实用类快捷键 1 常用熟悉的快捷键 CTRL+C(复制).CTRL+X(剪切).CTRL+Z(撤销).CTRL+F(查找).CTRL+H(搜索文件或字符串).CTRL+Y(重做).CTRL+/(双 ...

  2. linux系统中errno与error对照表

    1.使用了一个小程序输出所有的errno对应的error字符串,代码如下 #include <errno.h> void showError(int err){ printf(" ...

  3. OSG使用更新回调来更改模型

    OSG使用更新回调来更改模型 转自:http://blog.sina.com.cn/s/blog_668aae7801017gl7.html 使用回调类实现对场景图形节点的更新.本节将讲解如何使用回调 ...

  4. C#读取XML文件的方法

    先写一个xml文件: <?xml version="1.0" encoding="utf-8" ?> <bookste> <!-- ...

  5. WinForm 快捷键设置(转载)

    1.Alt+*(按钮快捷键) 按钮快捷键也为最常用快捷键,其设置也故为简单.在大家给button.label.menuStrip等其他控件的Text属性指定名称时,在其后面加上‘&’然后在加上 ...

  6. [转]AS3的垃圾回收

    GC和内存泄露无关 垃圾回收,这次是一个被无数人讨论过的传统话题. Action Script使用的是和Java相似的内存管理机制,并不会即时回收废弃对象的内存,而是在特定时间统一执行一次GC(Gab ...

  7. [LintCode] Decode Ways 解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  8. jquery中each遍历各种标签方法

    这写天用到的遍历jquery each方法比较频繁 刚好有时间,就在这里记录一下 jquery用的是bootstrap的线上文件 不需要导入 <!DOCTYPE html><html ...

  9. AJAX回调(调用后台方法返回数据)

    记得先要导入jquery.js. 格式一 $.ajax({"Key1":"value1","key2":"value2" ...

  10. GsonUtils.java

    package com.vcredit.ddcash.batch.util; import java.util.ArrayList;import java.util.List; import org. ...