1
我試圖實現一個搜索欄到我的網站,它不工作,我似乎無法弄清楚爲什麼。搜索形式如下:Django搜索欄問題
<form class="navbar-form navbar-left" role="search" method="GET" action="{% url 'search' %}">
<div class="form-group">
<input type="text" class="form-control" name="q" value="{{request.GET.q}}">
</div>
<button type="submit" class="btn">Search</button>
</form>
url.py:
url(r'^search/$', views.SearchView, name='search'),
views.py:
def SearchView(request):
products = Photos.objects.all()
query = request.GET.get("q")
if query:
products = products.filter(Q(category__contains=query)).distinct()
return render(request, 'urcle/search.html', {'products': products})
else:
return render(request, 'urcle/search.html', {'products': products})
search.html:
{% extends 'urcle/base.html'%}
{%block content%}
{% if products %}
<div id="inner" >
{% for item in products %}
<div id = 'content' align="center" ></div>
<div class="col-sm-4 col-lg-2" style="width:30%" >
<div class="thumbnail" align="left" >
<a href="{{item.name}}">
<img src="http://ec2-54-194-123-114.eu-west-1.compute.amazonaws.com/images/{{ item.name }}.jpg" class="img-responsive">
</a>
<div class="caption" >
<a href="#">{{item.title}}</a> </li>
<br/>
</div>
</div>
</div>
{% cycle '' '' '' '' '' '<div class="clearfix visible-lg"> </div>' %}
{% endfor %}
</div>
{% else %}
<h1>nothing to see here!!!</h1>
{% endif %}
{%endblock%}
什麼是真正竊聽我所看到的只是第一部分在從base.html得到擴展甚至沒有在else語句的標籤顯示,任何人都知道最新?
檢查base.html文件包含{%塊含量%} {%端塊%}。 –