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。
更多建议: