比较字典值的子字符串

2024-10-01 00:25:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想将“术语”与字典的值进行比较,特别是值的子字符串。这是必要的,因为不同模块的值格式不同。例如:module1='Doe',module2='Jane Doe'。在这种情况下比较的术语是“Doe”。我该如何着手解决这个问题?谢谢!你知道吗

你知道吗搜索.html你知道吗

{% if tickets %}
Tickets found:
<table class="table">
    <thead>
    <tr>
        <th>ID</th>
        <th>Company</th>
        <th>Summary</th>
    </tr>
    </thead>
    <tbody>
    {% for ticket in tickets %}
    <tr>
        <td> {{ ticket.id }} </td>
        <td> {{ ticket.company.name }} </td>
        <td> {{ ticket.summary }} </td>
    </tr>
    {% endfor %}
    {% endif %}
    </tbody>
</table>

你知道吗视图.py你知道吗

def search_bar(request):
term = request.GET.get('term')

if term:
    results = objCW.search_companies(term) + objCW.search_contacts(term)
    tickets = objCW.search_tickets_by_company(term) + objCW.search_tickets_by_contact(term)
    context = {'results': results, 'tickets': tickets}
    return render(request, 'website/search.html', context)
else:
    context = {'': ''}
    return render(request, 'website/search.html', context)

Tags: searchrequesthtmlcontexttableticketresultstr