无法找出为什么我不断出现以下错误:
TypeError at /boats/reversion/ count() takes 1 positional argument but 2 were given
#views
…
…
…
memory_limiter = BoatImage.objects.filter(boat_id__isnull=True).exclude(
memory__in=existing_boats_pk).values_list("memory", flat=True)
for i in memory_limiter:
if memory_limiter.count(i) > 3:
memory_limiter.remove(i)
壳牌对内存限制器的看法:
>>> for memory in memory_limiter:
... print(memory, type(memory))
...
93 <class 'int'>
93 <class 'int'>
93 <class 'int'>
93 <class 'int'>
93 <class 'int'>
93 <class 'int'>
93 <class 'int'>
100 <class 'int'>
102 <class 'int'>
102 <class 'int'>
102 <class 'int'>
>>> memory_limiter
<QuerySet [93, 93, 93, 93, 93, 93, 93, 100, 102, 102, 102]>
>>>
以下方法产生相同的结果:
for i in [ x for x in memory_limiter]:
if memory_limiter.count(i) > 3:
memory_limiter.remove(i)
问题是伯爵怎么了?我将这个列表复制粘贴到一个单独的*.py
模块,在那里它可以正常工作…
尝试将qs转换为迭代器-相同的结果。你知道吗
在单独的模块中
a = [93, 93, 93, 93, 93, 93, 93, 100, 102, 102, 102]
for i in a:
if a.count(i) > 3:
a.remove(i)
print(a)
----- >[93, 93, 93, 100, 102, 102, 102]
django在这里没什么问题。你知道吗
您的代码在
list
上工作。但是Django的QuerySet
和python的list
是不同的对象,使用不同的方法。你知道吗但你可以这样做。这应该管用(IMHO)。你知道吗
相关问题 更多 >
编程相关推荐