python - 如何通过避免行名称等来仅打印数据库中的值(在 Django 中)

标签 python mysql django

我使用 Django ,数据库是 mysql ,当我从行打印 id 时,其打印 { id: 45 } ,但我只需要结果 45 ...有人可以有帮助吗?

itemList = todoitem.objects.filter(content__in=wordlist).values("id")

最佳答案

你可以做一个values_list(..) [Django-doc]flat=True 作为参数:

itemList = todoitem.objects.filter(
    content__in=wordlist
).<b>values_list('id', flat=True)</b>

请注意,这不是一个列表,它是一个QuerySet。然而,查询集中的项目在这里是 int,而不是字典,也不是列表。

关于python - 如何通过避免行名称等来仅打印数据库中的值(在 Django 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56100658/

相关文章:

python - python 中的线程和动态列表问题

python - 停止 celery 工作人员从所有队列中消费

mysql - 重用子查询中的计算数据

php - 如果未在多对多表中注册,如何选择行

php - 访问关联数组 php pdo 时出现问题

django - Ubuntu 上的 Apache 错误 ERROR : Site (SiteName) does not exist

python - 大型数据库如何处理锁?

python - 用另一个包含越界值的数组索引一个 numpy 数组

python - 如何计算 GeoDjango 中两点之间的 3D 距离(包括高度)

python - Django objects.dates ('date' , 'month' ) 查询关闭一个月