效果:
def search(request):
if request.method == 'GET':
return render(request, 'search_index.html')
elif request.method == 'POST':
kw = request.POST.get('db_search')
if not kw or len(kw.split())==0:
messages.error(request, "Please enter at lease one keyword")
return render(request, 'search_index.html')
kl = kw.split()
results = XXXX.objects.filter(info__contains=kl[0])
if len(kl) > 1:
for i in kl[1:]:
results = results.filter(info__contains=i)
dbs_info = {
'kw': kw,
'results': results,
}
return render(request, 'search_results.html', dbs_info)