Flask Version 0.8 至 Version 0.10

2021-08-11 21:27 更新

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

從函數(shù)中返回元組的操作被簡化了,返回元組時(shí)你不再需要為你創(chuàng)建的 response 對象定義參數(shù)了, 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. 如果你的代碼依賴于舊版本,可以通過創(chuàng)建 Flask 的子類簡單地解決這個(gè)問題

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

如果你維護(hù)的擴(kuò)展曾使用 _request_ctx_stack ,可以考慮降至替換為 _app_ctx_stack,但仍須檢查是否可行。例如,對于操作數(shù)據(jù)的擴(kuò)展來說,app context stack 更說得通,在請求無關(guān)的用例中使用它比 request stack 處理起來更容易。

Version 0.10

版本 0.9 到 0.10 最大變化在于 cookie 序列化格式從 pickle 轉(zhuǎn)變?yōu)榱藢iT的 JSON 格式, 這一更新是為了避免密鑰丟失時(shí)遭受黑客攻擊帶來損失。在更新是你會注意到以下兩大主要變化: 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 數(shù)據(jù),你可以使用 Flask 擴(kuò)展 Flask-OldSessions_ 來代替原先的 session。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號