日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Flask教程:Flask銷毀回調(diào)

銷毀回調(diào)是是特殊的回調(diào),因為它們在不同的點上執(zhí)行。嚴(yán)格地說,它們不依賴實際 的請求處理,因為它們限定在 ?RequestContext? 對象的生命周期。 當(dāng)請求上下文出棧時, ?teardown_request()? 上綁定的函數(shù)會 被調(diào)用。

這對于了解請求上下文的壽命是否因為在 with 聲明中使用測試客戶端或在命令行 中使用請求上下文時被延長很重要:

with app.test_client() as client:
    resp = client.get('/foo')
    # the teardown functions are still not called at that point
    # even though the response ended and you have the response
    # object in your hand

# only when the code reaches this point the teardown functions
# are called.  Alternatively the same thing happens if another
# request was triggered from the test client

從這些命令行操作中,很容易看出它的行為:

>>> app = Flask(__name__)
>>> @app.teardown_request
... def teardown_request(exception=None):
...     print 'this runs after request'
...
>>> ctx = app.test_request_context()
>>> ctx.push()
>>> ctx.pop()
this runs after request
>>>

注意銷毀回調(diào)總是會被執(zhí)行,即使沒有請求前回調(diào)執(zhí)行過,或是異常發(fā)生。測試系 統(tǒng)的特定部分也會臨時地在不調(diào)用請求前處理器的情況下創(chuàng)建請求上下文。確保你 寫的請求銷毀處理器不會報錯。


網(wǎng)站標(biāo)題:創(chuàng)新互聯(lián)Flask教程:Flask銷毀回調(diào)
鏈接地址:http://www.5511xx.com/article/dpodish.html