在templates/front/下创建详情页面front_pdetail.html

编辑front.views.py创建详情页的视图函数

from flask import abort
... @bp.route('/p/<post_id>/')
def post_detail(post_id):
post = PostModel.query.get(post_id)
if not post:
abort(404)
return render_template('front/front_pdetail.html', post=post)

上面写了,如果帖子不存在,则返回404,我们先创建个404页面

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>BBS论坛404页面</title>
</head>
<body>
您要找的页面已经到火星去了~~
<div>
<a href="/">回到首页</a>
</div>
</body>
</html>

front_404.html

然后我们写个钩子函数,返回404的页面, 编辑front.hooks.py

@bp.errorhandler
def page_not_found():
return render_template('front/front_404.html'),404

帖子详情页面布局

编辑front_pdetail.html

{% extends 'front/front_base.html' %}

{% block title %}
{{ post.title }}
{% endblock %} {% block head %}
<link rel="stylesheet" href="{{ url_for('static', filename='front/css/front_pdetail.css') }}">
{% endblock %} {% block body %}
<div class="lg-container">
<div class="post-container">
<h2>{{ post.title }}</h2>
<p class="post-info-group">
<span>发表时间:{{ post.create_time }}</span>
<span>作者:{{ post.author.username }}</span>
<span>所属板块:{{ post.board.name }}</span>
<span>阅读数:{{ post.read_count }}</span>
<span>评论数:0</span>
</p>
<article class="post-content" id="post-content" data-id="{{ post.id }}">
{{ post.content|safe }}
</article>
</div> </div>
<div class="sm-container"></div>
{% endblock %}

front_pdetail.html

.post-container{
border: 1px solid #e6e6e6;
padding: 10px;
} .post-info-group{
font-size: 12px;
color: #8c8c8c;
border-bottom: 1px solid #e6e6e6;
margin-top: 20px;
padding-bottom: 10px;
} .post-info-group span{
margin-right: 20px;
} .post-content{
margin-top: 20px;
} .post-content img{
max-width: 100%;
}

front_pdetail.css

在首页配置帖子的链接

Flask实战第62天:帖子详情页布局的更多相关文章

  1. 用Vue来实现音乐播放器(四十):歌单详情页布局以及Vuex实现路由数据通讯

    1.歌单详情页是推荐页面的二级路由页面 将推荐页面歌单的数据传到歌曲详情页面  利用vuex 1.首先在state下定义一个歌单对象 disc{} 2.在mutaions-types中  定义一个别名 ...

  2. 一百四十二:CMS系统之帖子详情页面布局

    定义一个404页面 <!DOCTYPE html><html lang="en"><head> <meta charset="U ...

  3. BBS-文章详情页、点赞功能

    文章详情页--布局中header和左边区域不变--用到继承 home_site和article_detail只是布局 中心区域 只是右侧不同-----用到继承原理 -------- url # 文章详 ...

  4. java亿级流量电商详情页系统的大型高并发与高可用缓存架构实战视频教程

    亿级流量电商详情页系统的大型高并发与高可用缓存架构实战 完整高清含源码,需要课程的联系QQ:2608609000 1[免费观看]课程介绍以及高并发高可用复杂系统中的缓存架构有哪些东西2[免费观看]基于 ...

  5. mxonline实战13,授课讲师列表页,详情页,index页面全局导航

    对应github地址:第13天   把teacher-list.html和teacher-detail.html拷贝过来   一. 授课讲师列表页   1. 修改html文件 把org-list.ht ...

  6. mxonline实战11,课程详情页2,课程章节页

    对应github地址:第11天   一. 课程详情页2   1. 课程详情页第2块中的课程介绍中,修改course-detail.html中代码,搜索课程详情,找到如下代码

  7. mxonline实战10,课程列表页,课程详情页1

    对应github地址:第10天   一. 课程列表页   1. 拷贝course-list.html到templates目录中 2. 编写url和view 在courses/views.py中新加

  8. 25、Django实战第25天:讲师详情页

    1.复制teacher-detail.html到templates目录下 2.编辑teacher-detail.html,继承base.html 3.编辑organization.view.py cl ...

  9. 20、Django实战第20天:课程详情页

    1.把course-detail.html复制到templates目录下 2.编辑course-detail.html,分析页面,继承base.html 3.编辑courses.views .... ...

随机推荐

  1. [洛谷P3444] [POI2006]ORK-Ploughing

    洛谷题目链接[POI2006]ORK-Ploughing 题目描述 Byteasar, the farmer, wants to plough his rectangular field. He ca ...

  2. jsp 内置对象二

    1.什么是session ? (1)session 表示客户端与服务器的一次回话. 2)Web中的session指的是用户在浏览某个网站时,从进入网站到浏览器关闭所经过的这段时间,也就是用户浏览这个网 ...

  3. 通过.NET客户端异步调用Web API(C#)

    在学习Web API的基础课程 Calling a Web API From a .NET Client (C#) 中,作者介绍了如何客户端调用WEB API,并给了示例代码. 但是,那些代码并不是非 ...

  4. 安装在Linux下的jenkins执行windows下的bat命令

    launch method里面没有 launch agent via java web start 默认是disable 需要改成random 转载自: http://blog.csdn.net/so ...

  5. 【bzoj1594-猜数游戏】线段树

    题解: 矛盾只有两种情况: 一.先前确定了x在区间(l,r),但是现在发现x在区间(l1,r1),并且两个区间不相交. 二.一个区间的最小值是x,这个区间中有一个子区间的最小值比x更小. 首先可以明确 ...

  6. 【Codeforces】868C. Qualification Rounds

    [题目]C. Qualification Rounds [题意]给定n个问题和K个人,给定每个人知道的问题列表,求能否找到一个非空问题集合,满足每个人知道的集合中问题数量都不超过集合总题数的一半.n& ...

  7. B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. Linux命令--hostname和uname

    hostname命令 hostname命令用于显示和设置系统的主机名称.环境变量HOSTNAME也保存了当前的主机名.在使用hostname命令设置主机名后,系统并不会永久保存新的主机名,重新启动机器 ...

  9. C++转换构造函数和隐式转换函数 ~ 转载

    原文地址: C++转换构造函数和隐式转换函数 用转换构造函数可以将一个指定类型的数据转换为类的对象.但是不能反过来将一个类的对象转换为一个其他类型的数据(例如将一个Complex类对象转换成doubl ...

  10. python基础===zmail,收发邮件的模块

    项目地址: GitHub:https://github.com/ZYunH/zmail  介绍: https://mp.weixin.qq.com/s?__biz=MzAxMjUyNDQ5OA==&a ...