Day 9 Django Message
Measuring programming progress by lines of code is like measuring aircraft building progress by weight.——Bill Gates(微軟創(chuàng)始人)
Quite commonly
in web applications, you need to display
a one-time
notification
message to the user after processing
a form or some other types of user input.
在web應(yīng)用中很常見的一件事是,在處理完表單提交或者其他類型的用戶輸入時(shí)闹究,你需要把一些只顯示一次的消息展現(xiàn)給用戶填抬。
Due to
the way cookies work, the behavior of any backends that make use of cookies or sessions is undefined
when the same client makes multiple
requests that set or get messages in parallel
.
由于瀏覽器中cookie的工作方式,當(dāng)客戶端發(fā)出涉及到消息讀寫的并發(fā)請(qǐng)求時(shí)拔恰,任何有用到cookie或者session的web后端的響應(yīng)行為都是不確定的抑片。
For example, if a client initiates
a request that creates a message in one tab
and then another that fetches
messages in another tab
, before the first tab
redirects
, the message may appear in the second tab
instead of
the first tab
where it may be expected.
比如仇味,如果在一個(gè)tab中發(fā)起了創(chuàng)建消息的請(qǐng)求,然后馬上在另一個(gè)tab中獲取消息材失,那么這個(gè)消息就有可能出現(xiàn)在第二個(gè)tab中痕鳍,而非我們所期望的第一個(gè)tab。
In short
, when multiple
simultaneous
requests from the same client are involved
, messages are not guaranteed
to be delivered
to the same tab
that created them nor, in some cases, at all.
簡單地說,當(dāng)牽扯到客戶端同時(shí)發(fā)出的多個(gè)請(qǐng)求時(shí)笼呆,Django無法保證接收到消息的窗口就是創(chuàng)建它的那個(gè)窗口熊响,在某些情況下,甚至一定不會(huì)是創(chuàng)建它的窗口诗赌。
Note
that this is typically
not a problem in most applications and will become a non-issue
in HTML5, where each tab
will have its own browsing context.
注意汗茄,這在大多數(shù)應(yīng)用中并不是一個(gè)問題,尤其在HTML5中铭若,就更不值一提了洪碳。因?yàn)镠TML5中,每個(gè)tab會(huì)有屬于它們自己的瀏覽上下文叼屠。
本文選自:
https://docs.djangoproject.com/en/2.0/ref/contrib/messages/
生詞 | 音標(biāo) | 釋義 |
---|---|---|
commonly | [?kɑ:m?nli] | adv. 通常地瞳腌,一般地 |
display | [d??sple?] | v. 呈現(xiàn);展現(xiàn) |
one-time | [?w?n?ta?m] | adj. 只有一次的 |
notification | [?no?t?f??ke??n] | n. 通知 |
process | [?pro?ses] | v. 處理 |
due to | 因?yàn)榫涤辏捎?/td> | |
undefined | [??nd??fa?nd] | adj. 未闡明的嫂侍;未定義的 |
in parallel | 并發(fā)地 | |
initiate | [??n??ie?t] | v. 發(fā)起 |
tab | [t?b] | n. 標(biāo)簽頁面 |
fetches | [f?t?] | v. 獲取 |
redirect | [?rid??r?kt] | n. 返回;重定向 |
instead of | 而不是 | |
in short | 簡而言之 | |
multiple | [?m?lt?p?l] | adj. 大量的 |
simultaneous | [?sa?ml?te?ni?s] | adj. 同時(shí)的荚坞;并發(fā)的 |
involved | [?n?vɑ:lvd] | adj. 受牽扯的 |
guarantee | [?ɡ?r?n?ti] | v. 保證 |
deliver | [d??l?v?] | v. 發(fā)送 |
note | [no?t] | v. 注意 |
typically | [?t?p?kl?] | adv. 通常 |
non-issue | 不成問題的問題 |