Skip to content

文章内容数据

后端-文章数据展示

查询文章数据并返回

python
@index_bp.get("/article/<int:article_id>")
@jwt_required(optional=True)
def article_view(article_id):
    article: ArticleORM = ArticleORM.query.get(article_id)
    try:
        article: ArticleORM = ArticleORM.query.get(article_id)
    except Exception as e:
        current_app.logger.error(f'查询文章数据失败:{e}')
        abort(404)
    return render_template(
        "forum/article.html",
        current_user=current_user,
        article=article,
    )

数据未找到页面(404)暂不实现,后续再实现

前端模板实现

html
<h3>{{ article.title }}</h3>
<div class="detail_about">
    <span class="time_source">{{ article.create_at }}</span>
    <span class="author"> 来源: {{ article.source }}</span>
    <span class="comment_count">{{ article.clicks }}</span>
</div>

<p class="summary">
    {{ article.digest }}
</p>

{{ article.content | safe }}