Python快速建站系列-Part.Two-结构化和布局
|版权声明:本文为博主原创文章,未经博主允许不得转载。
首先明确我们要建一个什么样的站,作为教程(也算自己使用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-结构化和布局的更多相关文章
- Python快速建站系列-Part.One-组装开发环境
|版权声明:本文为博主原创文章,未经博主允许不得转载. 源代码都在github上:SmallStudyStation 现在是个demo,但回来会租个服务器,等功能完善了放到服务器上挂着,域名jusot ...
- Python快速建站系列-Part.Three-注册和登录
|版权声明:本文为博主原创文章,未经博主允许不得转载. 上一个Part已经给TSSS编好了一个简单的Web服务,网页的基础模版也写好了,那从这个Part开始就慢慢增加编写功能. 先写基础功能:注册和登 ...
- Python快速建站系列-Part.Six-文章内容浏览
|版权声明:本文为博主原创文章,未经博主允许不得转载. 其实到这里网站的基本功能已经完成一半了,第六节就完成文章内容的阅读功能. 完成blogview.html↓ {% extends "m ...
- Python快速建站系列-Part.Five.3-个人主页及资料页面
|版权声明:本文为博主原创文章,未经博主允许不得转载. 第五部分最后一节,完成个人主页里资料页面的个人资料的展示和修改功能,不过毕竟功能比较少,个人资料其实只有昵称一项,手动滑稽. 一如既往先写出来u ...
- Python快速建站系列-Part.Five.2-个人主页及文章列表
|版权声明:本文为博主原创文章,未经博主允许不得转载. 从usercen.html就可以发现我为个人主页设了三个分开的小版面:写文章.个人文章目录.个人资料 所以按顺序Part.Five的第二部分就完 ...
- Python快速建站系列-Part.Five.1-个人主页及发表文章
|版权声明:本文为博主原创文章,未经博主允许不得转载. 现在的TSSS已经有了注册和登录的功能,首页的内容也填充好了,那这一节就完成用户个人主页的内容和发表文章功能的实现. 先完成用户个人主页的use ...
- Python快速建站系列-Part.Four-首页内容填充
|版权声明:本文为博主原创文章,未经博主允许不得转载. Part.Three中实现了注册和登录的功能,那这一节完成主页内容的填充,并且主页中要实现简单的可以查找代码的功能. 而且有于公共代码部分存储在 ...
- PHPCMS快速建站系列之搜索功能
默认模板的搜索功能代码 <div class="bd"> <form action="{APP_PATH}index.php" method= ...
- PHPCMS快速建站系列之自定义分页函数
内容分页的实现方法:{pc:content action="lists" catid="$catid" order="id DESC" nu ...
随机推荐
- iis中MIME类型的介绍与使用
今天在服务器上碰到由.mp3格式转化生成的.m4r格式不能被浏览器访问(MP3与m4r在同个域名目录下eg:www.abc.com/1.m4r) 解决办法: 1.选中文件所在的站点: 2.找到MIME ...
- 在springmvc中,获取Connection接口
ServletContext context = request.getSession().getServletContext();WebApplicationContext wac = WebApp ...
- return和finally的执行顺序
创建一个类,新建一个方法: public class Demo { public int get() { int x=1; try { x++; return x; }finally{ ++x; } ...
- input相关问题总结
1. 禁止为所有被激活的输入框添加边框 *:focus {outline: none} 2. 禁止为被激活的输入框添加边框,说明:".abc"为输入框对象自定义添加的class类命 ...
- js 页码分页的前端写法
<script type="text/javascript"> var curPage = 1;//当前页码 var total;//总页数 $(function () ...
- php引用&符号详解——————给变量起小名
学习了这篇博客[http://blog.csdn.net/jiedushi/article/details/6428585] php中引用采用的是“写时拷贝”的原理,就是除非发生写操作,指向同一个地址 ...
- jquery-validation 使用
jquery-validation 使用 一.用前必备 官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: ...
- Bootstrap Chart组件使用分享
图表组件Chart.js是Bootstrap比较好用的组件之一,与一款收费的组件highchart类似,效果上来看免费与收费的产品相差还是有一点点的,不过功能上差不多能满足我们项目的需要.下面这段JS ...
- Unity3d优化
检测方式: 一,Unity3D 渲染统计窗口 Game视窗的Stats去查看渲染统计的信息: 1.FPS fps其实就是 frames per second,也就是每一秒游戏执行的帧数,这个数值越小, ...
- ACM Binary String Match
#include <stdio.h> #include <string.h> #include <stdlib.h> void SubString(char sub ...