Hello everyone, I encountered the error "object is not iterable" and do not understand how to solve it:
there is a code snippet views.py
def search(request): try: q = request.POST['clientSearch'] result = News.objects.get(pk=q) context={'result': result} except News.DoesNotExist: raise Http404("News does not exist") return render(request,'news/search.html', context) when executing the request, an error occurs and debugger refers to my template, on the 1st line:
{% for result in result %} {{ result.title }} {% endfor %} The most interesting thing is that with result = News.objects.filter(pk=q) everything works.
During Google, I realized that there is a News.objects.filter(pk=q) between News.objects.filter(pk=q) and News.objects.get(pk=q) , but I don’t understand what.
I would be very grateful if you tell me what the difference is between them and how to get the code with News.objects.get(pk=q) .