[Fixed]-How to render context to my template, what am i missing

1👍

You haven’t passed the query object to your template. The haystack examples inherit from SearchView class view, you’ve used function based views . I am guessing that’s the problem.

EDIT:
The real reason for this issue is that you’re urls.py points /main/search to haystack and thus the search function in the view isn’t called.
The solution would be to use something like SearchView and add the hotCat value into the context_dict. Then point the /main/search to this view.

Eg:

class OwnSearchView(SearchView):

    template='search/search.html',
    form_class=SearchForm

  def get_context_data(self, *args, **kwargs):
      context = super(OwnSearchView, self).get_context_data(*args, **kwargs)
      # do something
      context['hotCat'] = 'hotCat' #get this however you like
      return context

And then in your urls.py

url(r'^main/search/', OwnSearchView.as_view(),  name='haystack_search'),

)

You will need to add the variable values according to your code. Haystack docs have further details regarding the form_class and queryset.

Leave a comment