当前位置:网站首页>Flask博客实战 - 实现侧边栏最新文章及搜索
Flask博客实战 - 实现侧边栏最新文章及搜索
2022-06-25 09:38:00 【轻编程】
实现最新文章模块
这个就非常简单了,只需要将将最新文章传入blog的上下文中即可

在app/blog/views.py的inject_archive函数中新增代码如下:
@bp.context_processor
def inject_archive():
# 文章归档日期注入上下文
posts = Post.query.order_by(Post.add_date)
dates = set([post.add_date.strftime("%Y年%m月") for post in posts])
# 标签
tags = Tag.query.all()
for tag in tags:
tag.style = ['is-success', 'is-danger', 'is-black', 'is-light', 'is-primary', 'is-link', 'is-info', 'is-warning']
# 最新文章
new_posts = posts.limit(6)
return dict(dates=dates, tags=tags, new_posts=new_posts)在app/blog/templates/cate_list.html的侧边栏新增如下代码:
<div class="box is-shadow边栏推荐
- Armbian version name comparison
- Rxjs TakeUntil 操作符的学习笔记
- x86的编码格式
- 2台三菱PLC走BCNetTCP协议,能否实现网口无线通讯?
- Experience in writing C
- JS tool function, self encapsulating a throttling function
- Bug- solve the display length limitation of log distinguished character encoding (edittext+lengthfilter)
- Vscode attempted to write the procedure to a pipeline that does not exist
- ‘Flutter/Flutter. h‘ file not found
- SparseArray details
猜你喜欢

Kotlin advanced generic

ShardingSphere-Proxy 4.1 分庫分錶

Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial

Vscode attempted to write the procedure to a pipeline that does not exist

manhattan_ Slam environment configuration

ShardingSphere-Proxy 5.0 分库分表(一)

The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores

vscode试图过程写入管道不存在

How to build a wechat applet? How to open an applet?

瑞吉外卖项目(二)
随机推荐
Match a mobile number from a large number of mobile numbers
[buuctf.reverse] 117-120
广发证券靠谱吗?是否合法?开股票账户安全吗?
依赖属性、依赖附加属性以及类型转换
Redis(二)分布式锁与Redis集群搭建
ScheduleMaster分布式任务调度中心基本使用和原理
An auxiliary MVP architecture project quick development library -mvpfastdagger
Etcd教程 — 第四章 Etcd集群安全配置
Kotlin advanced - class
字符串 实现 strStr()
Pytorch_Geometric(PyG)使用DataLoader报错RuntimeError: Sizes of tensors must match except in dimension 0.
Fluent: target support file /pods runner / pods runner frameworks Sh: permission denied - stack overflow
Reza RA series - development environment construction
Gradle download warehouse is slow
Is it safe to open a stock account on the compass?
[Ruby on rails full stack course] course directory
WPF Prism框架
Neat Syntax Design of an ETL Language (Part 2)
Download the arm64 package of Debian on X86 computer
How to "transform" small and micro businesses (II)?