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 ...
随机推荐
- Linux的磁盘分区(1)
分区命名: 1.Linux下的分区命名不同于windows下的命名,对硬盘如IDE硬盘采用类似/dev/hdxy的方式来命名,其中hd表示分区所在的设备类型,如IDE硬盘,x表示硬盘盘号(a为基本主盘 ...
- jsp实现过滤器的简单例子
web.xml配置如下: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns=&quo ...
- 字典的快速赋值 setValuesForKeysWithDictionary
字典的快速赋值 setValuesForKeysWithDictionary 前言 在学习解析数据的时候,我们经常是这么写的:PersonModel.h文件中 @property (nona ...
- [CareerCup] 15.6 Entity Relationship Diagram 实体关系图
15.6 Draw an entity-relationship diagram for a database with companies, people, and professionals (p ...
- android-WebView
使用WebView 加载页面 一.加载页面 使用loadUrl() web资源:webView.loadUrl("http://www.baidu.com"); 本地文件用:web ...
- unity3d插件Daikon Forge GUI 中文教程5-高级控件listbox和progress bar的使用
3.3.listbox列表框 Atlas 图集: 下面应用到的精灵都是在这里的. ListBox中的内容: 背景精灵 图片的主颜色 Padding边距 Scrollbar 滚动条对象的预制体或者对象, ...
- Java面试题大全(二)
41.是否可以继承String类? String类是final类故不可以继承. 42.swtich是否能作用在byte上,是否能作用在long上,是否能作用在String上? switch(expr1 ...
- c++ basic 整理2
//拷贝函数 //拷贝构造函数是一种特殊的构造函数,函数的名称必须和类名称一致,它必须的一个参数是本类型的一个引用变量. //不显式指定拷贝函数时,编译器会生成默认拷贝函数. //使用默认拷贝函数 ...
- 20145337 《Java程序设计》第六周学习总结
20145337 <Java程序设计>第六周学习总结 教材学习内容总结 输入\输出 InputStream与OutputStream 从应用程序角度来看,如果要将数据从来源取出,可以使用输 ...
- VirtualMachine所支持的操作
在JDK中com.sun.tools.attach.VirtualMachine提供了一些从外部进程attach到jvm上,并执行一些操作的功能.VirtualMachine的子类HotSpotVir ...