V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
lovebeyondalways
V2EX  ›  Django

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

  •  
  •   lovebeyondalways ·
    piaokorg · 2016-11-15 14:36:47 +08:00 · 2851 次点击
    这是一个创建于 2722 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    2 条回复    2016-11-16 19:40:10 +08:00
    lovebeyondalways
        1
    lovebeyondalways  
    OP
       2016-11-15 19:49:20 +08:00
    ………………
    lovebeyondalways
        2
    lovebeyondalways  
    OP
       2016-11-16 19:40:10 +08:00
    ^^^^
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5526 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:10 · PVG 15:10 · LAX 00:10 · JFK 03:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.