开发者

haystack in a view

开发者 https://www.devze.com 2023-03-23 03:30 出处:网络
Folks. I just can\'t make the jump from the Haystack tutorial/docs to my (simple) application. I\'ve got Haystack/Whoosh working per the tutorial, and serving results. Now, instead of a separate sear

Folks. I just can't make the jump from the Haystack tutorial/docs to my (simple) application.

I've got Haystack/Whoosh working per the tutorial, and serving results. Now, instead of a separate search page, I want to search from a form on (say) my archive page and serve the results back into the same page.

I've got this going and showing the search form, and returning the query:

def blog_list(request, template_name="blog/blog_list.ht开发者_如何学Goml"):
    query=request.GET.get('q','')
    form=ModelSearchForm({'q': query })

    extra_context = {
         'query': query,
        'form': form,
    }
    return object_list(
        request,
        queryset=Entry.live.all(),
        extra_context=extra_context
    )

But in the template, {% for result in page.object_list %} isn't returning anything. Half my problem is that I've no idea where page.object_list is coming from and can't fathom it from the tutorial/documentation.

Can anyone shed some light on this for me? Thank you.


You haven't passed in anything called page, so naturally it's empty. It doesn't "come from" anywhere, unless you specifically pass it in.

The bit you don't seem to be doing is actually performing the search and passing the results to the template. Look how it's done in Haystack's built-in basic_search view - it calls the form's .search() method, passes the results to the Paginator class, and then passes that to the context.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号