簡體   English   中英

可以使用元組,用 request.user 解構,django?

[英]possible to use tuple, deconstruct with request.user, django?

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

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

email將等於hello

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

(email, username) = request.user所以我不必繼續輸入request.user而是只需使用emailusername ,就像javascript工作方式一樣。

如果我執行上述操作,我會收到一條錯誤TypeError: object is not iterable

提前感謝您的任何建議和意見。

python 中的解構機制以“位置”方式工作(正如您在(email, username) = ('hello', 'user')中使用的那樣。

它不能以“命名”方式工作,就像您在(email, username) = request.user中嘗試的那樣,就像 javascript 所做的那樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM