代码之家  ›  专栏  ›  技术社区  ›  cmashinho

带kwargs的方法[重复]

  •  0
  • cmashinho  · 技术社区  · 8 年前

    当我想使用这种风格时,会出错。

    User.objects().update(kwargs)
    

    我该怎么做?

    附笔 这种风格效果很好

    User.objects().update(state=1)
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Community CDub    7 年前

    你想这么做 unpack the dictionary :

    User.objects().update(**kwargs)
    

    有关适当的问题链接,请参考@jonrsharpe。