感觉不如编译安装
Python 的环境管理确实烦,而且会出现版本之间不兼容的情况,所以有必要知道如何安装不同版本的 Python 并管理其环境.
本文系统环境为 Debian11, 虚拟环境工具使用的是 venv, 采用编译安装的方法. 截止此文创建时, Python 最新版本为 3.11.3
什么是 JWT
JWT: JSON Web Tokens,它是一种将 JSON 对象编码为没有空格,且难以理解的长字符串的标准。在具体上,它就是一段字符串,下面就是 FastAPI 文档中给出的例子
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
抽象地把它看成是这样的
aaaaaaaaaaaa.bbbbbbbbbbbb.cccccccccccc
什么是「依赖注入」
What is "Dependency Injection"
编程中的「依赖注入」是声明代码(本文中为路径操作函数 )运行所需的,或要使用的「依赖」的一种方式。
然后,由系统(本文中为 FastAPI)负责执行任意需要的逻辑,为代码提供这些依赖(「注入」依赖项)。
依赖注入常用于以下场景:
- 共享业务逻辑(复用相同的代码逻辑)
- 共享数据库连接
- 实现安全、验证、角色权限等……
上述场景均可以使用依赖注入,将代码重复最小化。
"Dependency Injection" means, in programming, that there is a way for your code (in this case, your path operation functions) to declare things that it requires to work and use: "dependencies".
And then, that system (in this case FastAPI) will take care of doing whatever is needed to provide your code with those needed dependencies ("inject" the dependencies).
This is very useful when you need to:
- Have shared logic (the same code logic again and again).
- Share database connections.
- Enforce security, authentication, role requirements, etc.
- And many other things...
All these, while minimizing code repetition.

之前我曾安利过 PasteImage 这个插件,用 VSCode 写博客/文档的时候,用它可以很快捷地在md文档中插入图片。
受某个友人影响,我也开始尝试 拥抱 webp了,近期的文章内的图片都已经压缩成了 webp 格式。但是 PasteImage 却不支持 webp 格式,于是我又想办法整出了今天这个解决方案,实现完全自动化的 压缩+插入图片。