1👍
✅
It doesn’t, it is just how subscripting request.POST
works: it will return the last picked item.
You should use .getlist(…)
[Django-doc] instead:
def search_view(request):
if request.method == 'POST':
psearch = request.POST.getlist('psearch')
images = Image.objects.filter(tags__name__in=psearch)
return render(
request, 'search.html', {'psearch': psearch, 'images': images}
)
else:
return render(request, 'search.html', {})
Note: Searching is usually done through a GET request, since that means the query is stored in the querystring and thus the URL. This makes it convenient to for example share the URL with the query to someone else, or bookmark the result. POST requests are usually used for state-changing actions, or for requests with sensitive data.
- [Answered ]-Django : can't return redirect in a sub function exception. The first function continues
Source:stackexchange.com