【问题标题】:How to show the results of a Haystack Query on a separate page如何在单独的页面上显示 Haystack 查询的结果
【发布时间】:2013-06-05 10:59:55
【问题描述】:

我有一个 index.html 用于实现我的表单:

...
{% block searchform%} {% endblock %}
...

在我的搜索/文件夹中,我有两个文件。

search.html,它是 index.html 的实际形式

{% extends 'index.html' %}

{% block searchform %}
    <form method="get" action="/results/">
        <table>
            {{ form.as_table }}
            <tr>
                <td>&nbsp;</td>
                <td>
                    <input type="submit" value="Search">
                </td>
            </tr>
        </table>
{% endblock %}


和文件 result.html,我想在其中查看我的搜索结果:

{% if query %}
<h3>Results</h3>
...
{% endif %}

urls.py:

from django.conf.urls import include, patterns, url
from dev_devices.views import *

urlpatterns = patterns('',
    url(r'^$', include('haystack.urls')),
    url(r'^results/$', results, name = 'results')
)

view.py

def results(request):
    return render_to_response('results.html')

我的问题是,没有结果显示。当我单击表单的提交按钮时,我将重定向到正确的文件 (results.html),但没有显示任何结果。

haystack (http://django-haystack.readthedocs.org/en/latest/tutorial.html#installation) 的安装指南示例运行良好。但是这个例子只是展示方式,如果表单和结果页面是同一个页面。

【问题讨论】:

  • 如果您曾经对您的 django 应用程序进行过发布请求,您应该能够拼凑出这是如何工作的。您要使用的视图需要进行实际搜索,然后将结果传递给模板。
  • 您没有将查询集或上下文从视图发送到results.html

标签: python django django-haystack


【解决方案1】:
def results(request):
    return render_to_response('results.html')

您在这里看到了一些结果吗?我不...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多