在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. CF911E Stack Sorting

    洛谷题目链接:CF911E Stack Sorting Codeforces题目链接:Stack Sorting 题意翻译 给你一排列的一部分,让你补全整个排列使其字典序最大并且经过一个栈调整顺序之后 ...

  2. 【Codeforces629C】Famil Door and Brackets [DP]

    Famil Door and Brackets Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample Inp ...

  3. springcloud(一):大话Spring Cloud(山东数漫江湖)

    研究了一段时间spring boot了准备向spirng cloud进发,公司架构和项目也全面拥抱了Spring Cloud.在使用了一段时间后发现Spring Cloud从技术架构上降低了对大型系统 ...

  4. 01背包入门 dp

    题目引入: 有n个重量和价值分别为Wi,Vi的物品.从这些物品中挑选出总重量不超过W的物品,求所有挑选方案中的价值总和的最大值. 分析: 首先,我们用最普通的方法,针对每个物品是否放入背包进行搜索. ...

  5. 【HNOI】trust 弦图最大独立集

    [题目描述]有n个人,每个人之间都有是否信任的关系,要求找出k个人,使得k个人之间彼此信任,且k最大,保证不信任的关系由多个三元环组成,且三元环之间只可能有公共点,没有公共边,且不存在任意一个节点不属 ...

  6. css文本垂直水平居中

    一.单行文本居中 .content{ height:100px; line-height:100px; text-align:center; border:1px solid red; } 效果图 二 ...

  7. 【bzoj4448】SCOI2015 情报传递

    树剖,可以相当于一个染色问题,以及询问先前节点的染色个数. 把第二种操作离线掉,然后用线段树模拟即可. #include<bits/stdc++.h> #define N 800010 # ...

  8. 使用IDEA从github中下载fastdfs-client-java

    由于在pom文件中加入依赖坐标无法将fastdfs-client-java下载下来,后来通过查资料,发现在中央仓库中没有定义该坐标.为此,使用idea从github下载fastdfs-client-j ...

  9. shell常见操作整理(更新)

    查看文件第20到30行的内容 法一:[root@oldboy ~]# seq 100 > ett.txt [root@oldboy ~]# head -30 ett.txt | tail -11 ...

  10. udp调用connect有什么作用(转)

    原文链接如下: http://blog.csdn.net/wannew/article/details/18218619 整理一下.1:UDP中可以使用connect系统调用 2:UDP中connec ...