当前位置:网站首页>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边栏推荐
- How much does a small program cost? How much does a small program cost? It's clear at a glance
- Match a mobile number from a large number of mobile numbers
- Flutter Gaode map privacy compliance error
- Jetpack compose layout (IV) - constraintlayout
- Swift recursively queries the array for the number closest to the specified value
- SparseArray details
- Nano data World Cup data interface, CSL data, sports data score, world cup schedule API, real-time data interface of football match
- (forwarding articles) after skipping multiple pages, shuttle returns to the first page and passes parameters
- 纳米数据世界杯数据接口,中超数据,体育数据比分,世界杯赛程api,足球比赛实时数据接口
- 汇付国际为跨境电商赋能:做合规的跨境支付平台!
猜你喜欢

Unique Wulin, architecture selection manual (including PDF)

Remove the mosaic, there's a way, attached with the running tutorial

Encoding format for x86

Wallys/MULTI-FUNCTION IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL

Learning notes of rxjs takeuntil operator

匯付國際為跨境電商賦能:做合規的跨境支付平臺!

独步武林,架构选型手册(包含 PDF)
![[buuctf.reverse] 117-120](/img/6c/8a90fff2bd46f1494a9bd9c77eeafc.png)
[buuctf.reverse] 117-120

Modbus协议与SerialPort端口读写

Reasons for Meiye to choose membership system
随机推荐
ShardingSphere-Proxy 5.0 分库分表(一)
Kotlin keyword and operator
Fluent creates, reads and writes JSON files
8、智慧交通项目(1)
How to do the wechat selling applet? How to apply for applets
Cubemx stm32f105rb USB flash drive reading and writing detailed tutorial
x86电脑上下载debian的arm64的包
Match a mobile number from a large number of mobile numbers
Android database security: after the user exits, the transaction rollback log still stores relevant data information
[buuctf.reverse] 117-120
字符串 最长公共前缀
How to apply for a widget on wechat how to get a widget on wechat
WPF Prism框架
STM32 receives data by using idle interrupt of serial port
Bug- solve the display length limitation of log distinguished character encoding (edittext+lengthfilter)
[buuctf.reverse] 121-125
CyCa 2022 children's physical etiquette primary teacher class Shenzhen headquarters station successfully concluded
SparseArray details
Kotlin advanced set
[MySQL learning notes 22] index