可能使用元组,用request.user解构,django吗?

问题描述 投票:1回答:1

通常,我知道元组可以用作

(email, username) = ('hello', 'user')

email将等于hello

但是我想知道我是否可以做类似的事情

[(email, username) = request.user,所以我不必继续键入request.user,而只需像email一样使用usernamejavascript

如果执行上述操作,我会得到一个错误,提示TypeError: object is not iterable

感谢您的任何建议。

javascript python django destructuring
1个回答
1
投票

python中的[[destructuring机制以“ positional”方式工作(就像您在(email, username) = ('hello', 'user')中使用的一样。

它无法像您在(email, username) = request.user中所尝试的那样,以

“ named”

的方式工作,就像javascript一样。
© www.soinside.com 2019 - 2024. All rights reserved.