Day 9 Django Message
Measuring programming progress by lines of code is like measuring aircraft building progress by weight.——Bill Gates(微软创始人)
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应用中很常见的一件事是,在处理完表单提交或者其他类型的用户输入时,你需要把一些只显示一次的消息展现给用户。
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的工作方式,当客户端发出涉及到消息读写的并发请求时,任何有用到cookie或者session的web后端的响应行为都是不确定的。
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.
比如,如果在一个tab中发起了创建消息的请求,然后马上在另一个tab中获取消息,那么这个消息就有可能出现在第二个tab中,而非我们所期望的第一个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.
简单地说,当牵扯到客户端同时发出的多个请求时,Django无法保证接收到消息的窗口就是创建它的那个窗口,在某些情况下,甚至一定不会是创建它的窗口。
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.
注意,这在大多数应用中并不是一个问题,尤其在HTML5中,就更不值一提了。因为HTML5中,每个tab会有属于它们自己的浏览上下文。
本文选自:
https://docs.djangoproject.com/en/2.0/ref/contrib/messages/
生词 | 音标 | 释义 |
---|---|---|
commonly | [ˈkɑ:mənli] | adv. 通常地,一般地 |
display | [dɪˈspleɪ] | v. 呈现;展现 |
one-time | [ˈwʌnˌtaɪm] | adj. 只有一次的 |
notification | [ˌnoʊtɪfɪˈkeɪʃn] | n. 通知 |
process | [ˈproʊses] | v. 处理 |
due to | 因为,由于 | |
undefined | [ˌʌndɪˈfaɪnd] | adj. 未阐明的;未定义的 |
in parallel | 并发地 | |
initiate | [ɪˈnɪʃieɪt] | v. 发起 |
tab | [tæb] | n. 标签页面 |
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. 同时的;并发的 |
involved | [ɪnˈvɑ:lvd] | adj. 受牵扯的 |
guarantee | [ˌɡærənˈti] | v. 保证 |
deliver | [dɪˈlɪvɚ] | v. 发送 |
note | [noʊt] | v. 注意 |
typically | [ˈtɪpɪklɪ] | adv. 通常 |
non-issue | 不成问题的问题 |
网友评论