[英]check for exact presence in a queryset django, jinja 2
就我而言,我有一个问题要检查查询集中是否存在 model 的确切字符串名称。 这是我的代码:
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 %}
在我的代码中, "my project"
和"project"
之间没有区别,如info.project_name
model。因为当我只有"my project"
时, "project"
一词存在于查询集中。 所以使用{% if info.project_name in filtered_projects %}
的效果相同( if
的条件将为True
),因为由于"my project"
,查询集中存在"project"
这个词。 我该怎么做才能检查其中的确切字符串?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.