40 - 个人博客项目-11- 文章详情

news/2024/10/25 17:29:08/

1. 新建 templates / article / detail.html 文章详情页面

        (1). 继承公共模板

{% extends 'base.html' %}{% block title %}文章详情
{% endblock %}

        (2). 编写文章样式

{% block styles %}{{ super() }}<style>#container {width: 1200px;margin: 0 auto;background-color: #83cae3;border-radius: 30px;padding: 20px;}#container h2 {text-align: center;}#shang {margin-top: 20px;}#shang span {margin-left: 10px;}#container p {overflow: auto;}#left {float: left;}#right {float: right;}#content {margin-top: 60px;}#item_left {display: inline-block;margin-top: 20px;}#item_left img {width: 60px;height: 60px;border-radius: 50px;margin-left: 100px;}#item_right {margin-top: 20px;display: inline-block;float: right;clear: both;margin-right: 65%;}</style>
{% endblock %}

        (3). 编写详情页面

{% block newcontent %}<div id="container"><div id="detail"><h2>{{ article.title }}</h2><div id="shang"><div id="left"><span>作者:{{ article.user.username }}</span><span>发布时间:{{ article.pdatetime }}</span></div><div id="right"><span class="glyphicon glyphicon-heart" aria-hidden="true"></span><spantag="0">{{ article.save_num }}</span><span class="glyphicon glyphicon-thumbs-up"aria-hidden="true"></span><span tag="0">{{ article.love_num }}</span></div></div><div id="content">{{ article.content|cdecode|safe }}</div><hr><div id="comment"><p>文章评论:</p><div><form action="#" method="post"><input type="hidden" name="aid" value="{{ article.id }}"><p><textarea name="comment" class="form-control" rows="5" cols="60">写下你的评论吧~</textarea></p><p><input type="submit" value="评论" class="btn btn-info"></p></form></div></div><p></p><div id="comment_item">{% if comments.items %}{% for comment in comments.items %}<div class="item"><div id="item_left"><img src="{% if comment.user.icon %}{{ url_for('static',filename=comment.user.icon) }}{% else %}{{ url_for('static',filename='images/touxiang.jpg') }}{% endif %}"></div><div id="item_right"><p><span>{{ comment.user.username }}</span><span>{{ comment.cdatetime }}</span></p><p>{{ comment.comment }}</p></div><hr>{% endfor %}{% else %}<div class="item">当前文章还没有评论,赶快发表意见吧</div>{% endif %}</div><div id="paginate"><nav aria-label="..."><ul class="pager"><li class="previous {% if not comments.has_prev %}disabled{% endif %}"><ahref="{{ url_for('article.article_detail') }}?page={{ comments.prev_num }}&aid={{ article.id }}"><spanaria-hidden="true">&larr;</span> 上一页</a></li><li class="next {% if not comments.has_next %}disabled{% endif %}"><ahref="{{ url_for('article.article_detail') }}?page={{ comments.next_num }}&aid={{ article.id }}">下一页<spanaria-hidden="true">&rarr;</span></a></li></ul></nav></div></div></div></div>
{% endblock %}

        (4). 编写js, 操作文本域点击后,默认内容清空

{% block scripts %}{{ super() }}<script>$(function () {//文本域$('textarea[name="comment"]').focus(function () {$(this).val("")})})</script>
{% endblock %}

2. 编写文章详情函数

# 文章详情页
@article_bp.route('/detail')
def article_detail():# 通过文章id获取文章对象article_id = request.args.get('aid')article = Article.query.get(article_id)# 获取文章分类types = Article_type.query.all()# 登录用户user = Noneuser_id = session.get("uid", None)if user_id:user = User.query.get(user_id)# 单独查询评论page = int(request.args.get("page", 1))comments = Comment.query.filter(Comment.article_id == article_id).order_by(-Comment.cdatetime).paginate(page=page,per_page=5)return render_template("article/detail.html", article=article, types=types, user=user, comments=comments)

3. 配置首页 index.html ,点击标题进入详情

 <h4><a href="{{ url_for('article.article_detail') }}?aid={{ article.id }}">{{ article.title }}</a></h4>


http://www.ppmy.cn/news/1075983.html

相关文章

产品展示视频拍摄制作流程

通过精心策划和制作的产品展示视频&#xff0c;展示产品的独特魅力和卓越功能。激发受众对产品的兴趣和购买欲望。为了确保产品展示视频的制作质量和效果&#xff0c;需要团队一起探讨具体的拍摄制作流程。深圳产品活动视频制作公司老友记小编为您分析产品展示视频的拍摄制作过…

iPhone 15 Pro与iPhone 13 Pro:最大的预期升级

如果你在2021年首次发布iPhone 13 Pro时就抢到了它,那么你的合同很可能即将到期。虽然距离iPhone 15系列还有几周的时间,但你可能已经在想:是时候把你的旧iPhone升级为iPhone 15 Pro了吗? 我们认为iPhone 13 Pro是你现在能买到的最好的手机之一。但如果你想在2023年晚些时…

计算机图形软件(三)6-2 图形功能、软件标准、其他图形软件包

图形功能 通用图形软件包为用户提供建立和管理图形的各种功能。这些子程序可以按照它们是否处理输出、输入、属性、变换、观察、图形分割或一般的控制而进行分类。 图形的基本构造块称为图形输出图元(graphics output primitive)。它们包括字符串和几何成分&#xff0c…

CentOS7查看和关闭防火墙

CentOS 7.0默认使用的是firewall作为防火墙 查看防火墙状态 firewall-cmd --state1 停止firewall systemctl stop firewalld.service1 禁止firewall开机启动 systemctl disable firewalld.service 1 转自&#xff1a;CentOS 6和CentOS 7防火墙的关闭 Centos7开放及查看…

RabbitMQ工作模式-路由模式

官方文档参考&#xff1a;https://www.rabbitmq.com/tutorials/tutorial-four-python.html 使用direct类型的Exchange,发N条消息并使用不同的routingKey,消费者定义队列并将队列routingKey、Exchange绑定。此时使用direct模式Exchange必须要routingKey完成匹配的情况下消息才…

华为云软件精英实战营——感受软件改变世界,享受Coding乐趣

机器人已经在诸多领域显现出巨大的商业价值&#xff0c;华为云计算致力于以云助端的方式为机器人产业带来全新机会 如果您是开发爱好者&#xff0c;想了解华为云&#xff0c;想和其他自由开发者交流经验&#xff1b; 如果您是学生&#xff0c;想和正在从事软件开发行业的大佬…

黑客组织“Anonymous”进行网络攻击抗议日本排放核污水

概述 近期全球都在关注日本核污水排放&#xff0c;起因是日本政府宣布&#xff0c;福岛第一核电站核污染水8月24日开始排入海洋&#xff0c;计划排放30年。那么这件事为什么会引起全球关注呢&#xff0c;大家通过美国对日本投放原子弹后果&#xff0c;导致广岛长崎任然处于核辐…

【C++初阶】stack的常见操作和模拟实现

&#x1f466;个人主页&#xff1a;Weraphael ✍&#x1f3fb;作者简介&#xff1a;目前学习C和算法 ✈️专栏&#xff1a;C航路 &#x1f40b; 希望大家多多支持&#xff0c;咱一起进步&#xff01;&#x1f601; 如果文章对你有帮助的话 欢迎 评论&#x1f4ac; 点赞&#x1…