Hello guys am building a search tool for postgres in django and am getting a lot of errors my output is in this way. <QuerySet [<Bindll: HIV-1 protease>, <Bindll: HIV-1 protease>, <Bindll: HIV-1 protease>
my code is
#Search resuts page.
{% extends 'Search/base.html' %}
{%block content %}
<center>
<br/><br/><br/><br/>
<h1>{% if ChemSearched %}
{{ChemSearched}}
<br>
<br>
{% for Bindll in tarname %}
{{tarname}}<br>
{% endfor %}
</h1></strong>
{% else %}
<strong>No Entry</strong>
{% endif %}
Copyright (c)
</center>
{% endblock %}
My database name in Bindll.
#Views.py page
from django.shortcuts import render
from django.http import HttpResponseRedirect
from .models import Bindll
def search_result(request):
if request.method == "POST":
ChemSearched = request.POST.get('ChemSearched')
tarname = Bindll.objects.filter(targetnameassignedbycuratorordatasource__contains=ChemSearched)
return render(request, 'Search/search_result.html',
{'ChemSearched':ChemSearched,'tarname':tarname})
else:
return render(request, 'Search/search_result.html',{})
using Postgresql and gitbash if related. Thanks in advace.
CodePudding user response:
In the forloop
you need to access the iterated variable not the actual context
{% for Bindll in tarname %}
{{Bindll}}<br>
{% endfor %}