大家好,我正在 django 中為 postgres 構建一個搜索工具,但出現了很多錯誤,我的輸出就是這種方式。<QuerySet [<Bindll: HIV-1 protease>, <Bindll: HIV-1 protease>, <Bindll: HIV-1 protease>
我的代碼是
#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 %}
我在 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',{})
如果相關,使用 Postgresql 和 gitbash。預先感謝。
uj5u.com熱心網友回復:
在forloop您需要訪問迭代變數而不是實際背景關系
{% for Bindll in tarname %}
{{Bindll}}<br>
{% endfor %}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/366797.html
標籤:Python 姜戈 PostgreSQL的
