BBS Forum (29)

BBS Forum (29)

29. Post details page layout

(1) front/hooks.py

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

(2) front/front_404.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <p>The page you were looking for flew to Mars! ! ! ! ! </p>
    <a href="/">Back to homepage</a>

</body>
</html>

(3) front/views.py

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

(4) front_index.html

 <p class="post-title"><a href="{{ url_for('front.post_detail',post_id=post.id) }}">{{ post.title }}</a></p>

(5) front_postdetail.html

{% extends'front/front_base.html' %}
{% from'common/_macros.html' import static %}

{% block title %}
    {{ post.title }}
{% endblock %}

{% block head %}

    <link rel="stylesheet" href="{{ static('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 time: {{ post.create_time }}</span>
                <Span> OF: {{post.author.username}} </span>
                <span>Board: {{ post.board.name }}</span>
                <span>Read count: {{ post.read_count }}</span>
                <span>Number of comments: 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 %}

(6) front/css/front_pdetail.css

*{
    margin:0;
    padding:0
}
.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%;
}
Reference: https://cloud.tencent.com/developer/article/1390477 BBS Forum (29)-Cloud + Community-Tencent Cloud