Categories: Flask 中文教程

Flask Version 0.8 至 Version 0.10

Version 0.8

Flask introduced a new session interface system. We also noticed that
there was a naming collision between flask.session the module that
implements sessions and flask.session which is the global session
object. With that introduction we moved the implementation details for
the session system into a new module called flask.sessions. If you
used the previously undocumented session support we urge you to upgrade.

If invalid JSON data was submitted Flask will now raise a
BadRequest exception instead of letting the
default ValueError bubble up. This has the advantage that you no
longer have to handle that error to avoid an internal server error showing
up for the user. If you were catching this down explicitly in the past
as ValueError you will need to change this.

Due to a bug in the test client Flask 0.7 did not trigger teardown
handlers when the test client was used in a with statement. This was
since fixed but might require some changes in your testsuites if you
relied on this behavior.

Version 0.9

从函数中返回元组的操作被简化了,返回元组时你不再需要为你创建的 response 对象定义参数了,
The behavior of returning tuples from a function was simplified. If you
return a tuple it no longer defines the arguments for the response object
you’re creating, it’s now always a tuple in the form (response, status,
headers) where at least one item has to be provided.
如果你的代码依赖于旧版本,可以通过创建 Flask 的子类简单地解决这个问题

class TraditionalFlask(Flask):
    def make_response(self, rv):
        if isinstance(rv, tuple):
            return self.response_class(*rv)
        return Flask.make_response(self, rv)

如果你维护的扩展曾使用 _request_ctx_stack ,可以考虑降至替换为
_app_ctx_stack,但仍须检查是否可行。例如,对于操作数据的扩展来说,app context stack
更说得通,在请求无关的用例中使用它比 request stack 处理起来更容易。

Version 0.10

版本 0.9 到 0.10 最大变化在于 cookie 序列化格式从 pickle 转变为了专门的 JSON 格式,
这一更新是为了避免密钥丢失时遭受黑客攻击带来损失。在更新是你会注意到以下两大主要变化:
all sessions that were issued before the upgrade are invalidated and you can
only store a limited amount of types in the session. The new sessions are
by design much more restricted to only allow JSON with a few small
extensions for tuples and strings with HTML markup.

为了避免破坏用户的 session 数据,你可以使用 Flask 扩展 Flask-OldSessions_ 来代替原先的 session。

冒牌SEO

前端开发者,欢迎大家一起沟通和交流。

Share
Published by
冒牌SEO

Recent Posts

vue:页面注入js修改input值

一般会直接这样写: let z…

8 小时 ago

聊聊vue3中的defineProps

在Vue 3中,defineP…

1 周 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

1 月 ago