Flask实战第62天:帖子详情页布局

在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

在首页配置帖子的链接

原文地址:https://www.cnblogs.com/sellsa/p/9750773.html

时间: 2024-08-30 11:39:55

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

首页列表显示全部问答,完成问答详情页布局。

首页列表显示全部问答: 将数据库查询结果传递到前端页面 Question.query.all() 前端页面循环显示整个列表. 问答排序 PY文件: @app.route('/') def index(): context={ 'touGao':Tougao.query.order_by('-time').all() } return render_template("index.html",**context) HTML: <div class="container&q

首页列表显示全部问答,完成问答详情页布局。在首页点击问答标题,链接到相应详情页。

1.首页列表显示全部问答: 将数据库查询结果传递到前端页面 Question.query.all() 前端页面循环显示整个列表. 问答排序 py文件: @app.route('/') def moban(): context = { 'wenda': Wenda.query.order_by('creat_time').all() } return render_template('moban.html',**context) html文件: <ul class="news-list&qu

首页列表显示全部问答,完成问答详情页布局

首页列表显示全部问答: 将数据库查询结果传递到前端页面 Question.query.all() 前端页面循环显示整个列表. 问答排序 # 遍历首页 @app.route('/') def base(): context = { 'username': Sent.query.all(), } return render_template('shouye.html',**context) 完成问答详情页布局: 包含问答的全部信息 评论区 以往评论列表显示区. <!DOCTYPE html> &l

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

1.歌单详情页是推荐页面的二级路由页面 将推荐页面歌单的数据传到歌曲详情页面  利用vuex 1.首先在state下定义一个歌单对象 disc{} 2.在mutaions-types中  定义一个别名 3.在mutations里面创建更改函数 4.在getters里面将该状态与组件映射 4.在recommed推荐主页引入mapMutations 5.在methods中去拓展mapMutations ...mapMutations({自定义函数名:' mutations-types中的别名 ' 

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

定义一个404页面 <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>404</title></head><body> 页面不存在 <div><a href="/">点击回到首页</a></div></body&g

亿级流量电商详情页系统的大型高并发与高可用缓存架构实战

对于高并发的场景来说,比如电商类,o2o,门户,等等互联网类的项目,缓存技术是Java项目中最常见的一种应用技术.然而,行业里很多朋友对缓存技术的了解与掌握,仅仅停留在掌握redis/memcached等缓存技术的基础使用,最多了解一些集群相关的知识,大部分人都可以对缓存技术掌握到这个程度.然而,仅仅对缓存相关的技术掌握到这种程度,无论是对于开发复杂的高并发系统,或者是在往Java高级工程师.Java资深工程师.Java架构师这些高阶的职位发展的过程中,都是完全不够用的.技术成长出现瓶颈,在自己

【实战】Ozon产品列表页及产品详情页nodejs爬虫

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { "name": "1", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "fs": "^0.

《亿级流量电商详情页系统实战:缓存架构+高可用服务架构+微服务架构》

视频教程:http://www.roncoo.com/course/view/af7d501667fe4a19a60e9467e6d2b3d9 升级说明: 该课程原本是123节课时,已于2017年7月份全部更新完毕.在原有123节课时的基础上,再免费新增70到80节左右的内容(注:课程大纲可能会做进一步优化,具体以最终更新为准),课程名将变更为<亿级流量电商详情页系统实战(第二版):缓存架构+高可用服务架构+微服务架构>简称第二版.本次免费新增内容将会从9月中旬开始更新,一直到10月底更新完毕

亿级流量电商详情页系统实战-缓存架构+高可用服务架构+微服务架构第二版视频教程

14套java精品高级架构课,缓存架构,深入Jvm虚拟机,全文检索Elasticsearch,Dubbo分布式Restful 服务,并发原理编程,SpringBoot,SpringCloud,RocketMQ中间件,Mysql分布式集群,服务架构,运 维架构视频教程 14套精品课程介绍: 1.14套精 品是最新整理的课程,都是当下最火的技术,最火的课程,也是全网课程的精品: 2.14套资 源包含:全套完整高清视频.完整源码.配套文档: 3.知识也 是需要投资的,有投入才会有产出(保证投入产出比是