首页 > 代码库 > Python快速建站系列-Part.Six-文章内容浏览

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

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

 

其实到这里网站的基本功能已经完成一半了,第六节就完成文章内容的阅读功能。


 

 

完成blogview.html↓

{% extends "main.html" %} 
{% block content %}
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>        <a class="navbar-brand" href="#">TSSS</a>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
            <li>
                <a href="/">首页</a>
            </li>
            <li>
                <a href="/code/codelist">算法</a>
            </li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">代码<strong class="caret"></strong></a>
                <ul class="dropdown-menu">
                    <li>
                        <a href="https://github.com/MU001999/The-algorithms">GitHub</a>
                    </li>
                    <li>
                        <a href="https://leetcode.com/">LeetCode</a>
                    </li>
                    <li>
                        <a href="https://www.codewars.com/">CodeWars</a>
                    </li>
                    <li class="divider">
                    </li>
                    <li>
                        <a href="https://github.com/sxy1001">SXY1001</a>
                    </li>
                    <li class="divider">
                    </li>
                    <li>
                        <a href="https://github.com/MU001999">MU001999</a>
                    </li>
                </ul>
            </li>
        </ul>
        <form class="navbar-form navbar-left" role="search" action="/" method="POST">
            <div class="form-group">
                <input type="text" class="form-control" name="codename" />
            </div> <button type="submit" class="btn btn-default">查找</button>
        </form>
        <ul class="nav navbar-nav navbar-right">
            <li>
                <a href="/user/usercen">{{ username }}</a>
            </li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">更多<strong class="caret"></strong></a>
                <ul class="dropdown-menu">
                    <li>
                        <a href="/user/usercen">个人中心</a>
                    </li>
                    <li>
                        <a href="/user/mycode">我的代码</a>
                    </li>
                    <li>
                        <a href="/user/plan">我的计划</a>
                    </li>
                    <li class="divider">
                    </li>
                    <li>
                        <a href="/sign/out">退出登录</a>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</nav>
<ul class="nav nav-tabs">
    <li>
        <a href="/user/usercen">写文章</a>
    </li>
    <li class="active">
        <a href="#">个人文章目录</a>
    </li>
    <li>
        <a href="/user/userinfo">个人资料</a>
    </li>
    <li class="dropdown pull-right">
        <a href="#" data-toggle="dropdown" class="dropdown-toggle">↓↓↓<strong class="caret"></strong></a>
        <ul class="dropdown-menu">
            <li>
                <a href="#">修改密码</a>
            </li>
        </ul>
    </li>
</ul><br>
<div class="page-header">
    <h1 class="text-center">
        {{ blog[‘title‘] }} <small>by  {{ blog[‘author‘] }}</small>
    </h1>
</div>
<br><br> 
{% raw blog[‘content‘] %} 
{% end %}

 

 

完成BlogHandler的一部分功能↓

class BlogHandler(web.RequestHandler):
    def get(self,input):
        if input == list:
            pass
        else:
            coll = self.application.db.blogs
            blog = coll.find_one({_id:ObjectId(input)})
            self.render(blogview.html,username = self.get_cookie(nickname),blog = blog)

文章阅读功能实现。

 

--Part.Six--

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