[英]check for exact presence in a queryset django, jinja 2
In my case, I have a question to check if the exact string name of a model does exist in a query set.就我而言,我有一个问题要检查查询集中是否存在 model 的确切字符串名称。 here is my code:
这是我的代码:
views.py:
if Despiking.objects.filter(user=request.user).exists():
filtered_projects = Despiking.objects.filter(user=request.user)
context.update({
'filtered_projects': filtered_projects.__str__(),
})
template.html:
{% if info.project_name in filtered_projects %}
<!-- some HTML elements -->
{% else %}
<!-- other HTML elements -->
{% endif %}
In my code, there is no difference between "my project"
and "project"
as info.project_name
model. because of that the "project"
word exists in the query set when I have only the "my project"
in it.在我的代码中,
"my project"
和"project"
之间没有区别,如info.project_name
model。因为当我只有"my project"
时, "project"
一词存在于查询集中。 so using {% if info.project_name in filtered_projects %}
works the same (the condition of if
will be True
) because that "project"
word exists in the query set because of the "my project"
.所以使用
{% if info.project_name in filtered_projects %}
的效果相同( if
的条件将为True
),因为由于"my project"
,查询集中存在"project"
这个词。 what can I do to check the exact string in it?我该怎么做才能检查其中的确切字符串?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.