这是一个 get 表单
<h4>站内搜索</h4>
<form action="/search/" method="get">
<div class="input-group">
<input class="form-control" type="text" name="q" placeholder="仅支持搜索文章题目" value="{{ request.GET.q }}">
<span class="input-group-btn">
<input class="btn btn-default" type="submit">
<span class="glyphicon glyphicon-search"></span>
</span>
</div>
</form>
django 的 url
url(r'^search/$', views.test_search),
views
def test_search(request):
q = request.GET.get("q")
if q:
category_post = article.objects.filter(title__icontains=q).distinct()
paginator = Paginator(category_post, 2)
page = request.GET.get('page')
try:
category_post = paginator.page(page)
except PageNotAnInteger:
category_post = paginator.page(1)
except EmptyPage:
category_post = paginator.paginator(paginator.num_pages)
if len(category_post) == 0:
return render(request, 'category.html', {"category_post": category_post, 'error': True})
else:
return render(request, 'category.html', {"category_post": category_post, 'error': False})
但是每次输入表单都给我返回一个空白页面 请问下这是怎么回事
1
lovebeyondalways OP ………………
|
2
lovebeyondalways OP ^^^^
|