我正在遍历所有用户的列表,并尝试检查当前用户是否正在关注他们。"in following“不起作用。我在哪里做错了?
following = [<User: testaccount1>, <User: testaccount2>]
all_users_list = <QuerySet [{'id': 1, 'username': ‘testaccount1’},{‘id': 2, 'username': ‘testaccount2’},{‘id': 3, 'username': ‘testaccount2’}]
{% for follow_user in all_users_list %}
{% if follow_user.username in following %}
FOLLOWING
{% else %}
Not Following
{% endfor %}
发布于 2018-12-17 05:43:59
停止使用values()
。有时它是有用的,但这不是其中之一。只需传递实际的查询集:User.objects.all()
。
其次,比较实际对象,而不是将用户名与列表进行比较:
{% if follow_user in following %}
https://stackoverflow.com/questions/53806205
复制相似问题