我试图用一个参数进行django查询过滤,并且还使用“ Q”,如下所示:
variables = Indicator.objects.filter(
type = constants_type_indicator_variable.variable,
Q(current_state = constants_current_state.valid) |
Q(current_state = constants_current_state.current_registered) |
Q(current_state = constants_current_state.re_opened) |
Q(current_state = constants_current_state.open_registered)
)
但是我在第一行“ Q”中得到了这个错误:
non-keyword arg after keyword arg
如果我仅使用“ Q”而不按该“类型”字段进行过滤,则它可以工作,但togheter会崩溃...
知道为什么吗?,在此先感谢。
试试这个:
variables = Indicator.objects.filter(
Q(current_state = constants_current_state.valid) |
Q(current_state = constants_current_state.current_registered) |
Q(current_state = constants_current_state.re_opened) |
Q(current_state = constants_current_state.open_registered),
type = constants_type_indicator_variable.variable,
)
该错误意味着您已在非关键字之前传递了kwargs,通常在python函数中,应先传递非关键字参数,然后再传递关键字args。这适用于所有python函数。
这篇文章对关键字功能参数有很好的解释。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句