Python快速建站系列-Part.Two-结构化和布局

时间:2022-12-30 20:40:35

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

首先明确我们要建一个什么样的站,作为教程(也算自己使用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&period;One-组装开发环境

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

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

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

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

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

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

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

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

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

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

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

  7. Python快速建站系列-Part&period;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 first---xml文件生成与解析

    一.使用append进行xml生成 Message类属性:private String body;        private String date;       private String a ...

  2. angularjs之browserTrigger

    今天推荐一款来自angularjs源码的单元测试辅助库browserTrigger,这是来自于ngScenario的一段代码.主要用户触发浏览器型行为更新ng中scope view model的值. ...

  3. node访问iis使用keep-alive设置不当

    iis默认的连接超时时间为2分钟 ,因此node程序使用keep-alive访问时,keep-alive的时间不应该超过2分钟,否则在请求完成后,node端继续保持连接,2分钟后iis断开连接,会导致 ...

  4. 轻量级应用开发之(08)UITableView

    一  UITableView基本介绍 在众多移动应⽤用中,能看到各式各样的表格数据 . 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView,UITableView继承自UISc ...

  5. C&num;正则表达式匹配任意字符

    原文:C#正则表达式匹配任意字符 不得不说正则很强大,尤其在字符串搜索上 匹配任意字符,包括汉字,换行符: [\s\S]*. 版权声明:本文为博主原创文章,未经博主允许不得转载.

  6. Java format 简单应用

    一.前言 String.format 作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,为了不止步于简单调用 String.format("Hello %s", &quot ...

  7. Eclipse&sol;MyEclipse 最最常用的快捷键

    F 键类 F2 显示详细信息 F3 跳到声明或定义的地方 Ctrl + 键类 Ctrl+1 快速修复 ( 最经典的快捷键 , 就不用多说了 ) Ctrl+D 删除当前行 Ctrl+E 快速显示当前 E ...

  8. ES6 Proxy和Reflect(下)

    construct() construct方法用于拦截new命令. var handler = { construct (target, args) { return new target(...ar ...

  9. mybatis源码分析(一)

    mybatis源码分析(sqlSessionFactory生成过程) 1. mybatis框架在现在各个IT公司的使用不用多说,这几天看了mybatis的一些源码,赶紧做个笔记. 2. 看源码从一个d ...

  10. 题解 P4008 【&lbrack;NOI2003&rsqb;文本编辑器】

    块状链表及其应用 思路楼上已经说的很清楚了 看代码注释 代码很丑 #include<cstdio> #include<cctype> #include<cstring&g ...