在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

相关文章: