TIME_ZONE
等于,'UTC'
而我有来自太多时区的用户。因此,当我使用 make POST
orPUT
与date
ortime
或dateTime
字段时,我将这些字段转换为UTC
before serializer.save()
。然后,当用户发出GET
请求时,我将相同的字段转换回用户的时区,即request.user.timezone
# simplified functions
def localize(usertimzone, date, type):
"""
type = 'date', 'time', 'datetime'
"""
from dateutil import parser
date = parser.parse(date)
if not date.tzinfo:
usertimzone = pytz.timezone(usertimzone)
date = usertimzone.localize(date)
utc_date = date.astimezone(pytz.utc)
return utc_date
def normalize(usertimzone, date, type):
current_user_tz = pytz.timezone(usertimzone)
date = current_user_tz.localize(date)
return date
Run Code Online (Sandbox Code Playgroud)
#usages example
def post(self, request, *args, **kwargs):
alert_date = …
Run Code Online (Sandbox Code Playgroud) 如果非负整数 N 的二进制表示不包含两个连续设置为 1 的位,则称为稀疏整数。例如,41 是稀疏的,因为其二进制表示为“101001”并且不包含两个连续的 1。另一方面,26 并不稀疏,因为它的二进制表示是“11010”并且包含两个连续的 1。
\n如果 P 和 Q 是稀疏的且 N = P + Q,则两个非负整数 P 和 Q 称为整数 N 的稀疏分解。
\n例如:
\n8 and 18 are a sparse decomposition of 26 (binary representation of 8 is "1000", binary representation of 18 is "10010");\n9 and 17 are a sparse decomposition of 26 (binary representation of 9 is "1001", binary representation of 17 is "10001");\n2 and 24 are not a sparse decomposition of 26; though …
Run Code Online (Sandbox Code Playgroud) 有什么办法可以通过 DOM 操作吗use_node_ref
?或者,如何document.query_selector()
使用红豆杉在 Rust 中进行操作?
use web_sys::HtmlInputElement;
use yew::{
function_component, functional::*, html,
NodeRef, Html
};
#[function_component(UseRef)]
pub fn ref_hook() -> Html {
let input_ref = use_node_ref();
let all_editables = input_ref.query_selector("[contenteditable]")
web_sys::console::(all_editables)
html! {
<div>
<input ref={input_ref} type="number" />
</div>
}
}
Run Code Online (Sandbox Code Playgroud)
目标:我有一个富文本编辑器应用程序。我有一个像这样的字符串形式的缩小的 html <h1> this is title</h1><p>hello world</>
,我需要获取 DOM 并更改innerHTML
以将其设置为此值。
目标2:innerHtml
当用户在元素中写入内容时,我还需要更新contenteditable
。例如,当用户输入时@john smith
,我将创建一个<a>
元素,其中包含指向 的个人资料的href
链接。John smith