Returning multiple (if all) objects.get in django then outputting to a template

Returning multiple (if all) objects.get in django then outputting to a template

I am trying to search through the database of users returning matches of the search querry, then I get this data and output it to a html. It works but I need to do this for multiple objects sometimes where this can get quite convoluted.

I am trying to search through the database of users returning matches of the search querry, then I get this data and output it to a html. It works but I need to do this for multiple objects sometimes where this can get quite convoluted.

views.py

def search_index(request):

if request.method == 'POST':
    form = SearchForm(request.POST)
    if form.is_valid():
        searchquerry = form.cleaned_data['searchquerry']
        try:
            found = (CustomUser.objects.get(username__icontains=searchquerry))
            foundname = (found.username)
            foundimage = (found.docfile)
            founddate = (found.date_joined)
            foundid = (found.id)
            # Redirect to the document list after POST
            return render(request, 'search_found.html', {'foundname':foundname,'foundimage':foundimage, 'founddate':founddate, 'foundid':foundid})
        except Exception as e:
            print(e)
else:
    form = SearchForm() # A empty, unbound form

return render(request, 'search_index.html', {'form':form})

forms.py

class SearchForm(forms.Form):
searchquerry = forms.CharField(label="Search for a username", max_length=100)

search_found.html

{% extends "_base.html" %}

{% block content %}

<html> <div class="foundbox"> <button class="add-friend">Add Friend</button> <button onclick="window.location.href='../profile/{{ foundid }}'" class="show-profile">Profile</button> <div class="foundimage"> <div class="foundimage_container"> <img class="foundimage_container" src="../{{ foundimage }}" onerror="this.onerror=null;this.src='../static/users/default.gif';"></img> </div> </div> <h2 class="foundtext">{{foundname}}</h2> <p class="founddate">Join date: {{founddate}}</p> </div> </html>

{% endblock %}

please mind the formatting.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Python Django Tutorial | Django Course

🔥Intellipaat Django course: https://intellipaat.com/python-django-training/ 👉This Python Django tutorial will help you learn what is django web development &...

Developing Restful APIs with Python, Django and Django Rest Framework

This article is a definitive guide for starters who want to develop projects with RESTful APIs using Python, Django and Django Rest Framework.