html 中表单为何总是无法向 django 的 url 传入数据

2016-11-15 14:36:47 +08:00
 lovebeyondalways

这是一个 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})

但是每次输入表单都给我返回一个空白页面 请问下这是怎么回事

2851 次点击
所在节点    Django
2 条回复
lovebeyondalways
2016-11-15 19:49:20 +08:00
………………
lovebeyondalways
2016-11-16 19:40:10 +08:00
^^^^

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/320665

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX