在会话中保存查询时出现django-haystack问题

时间:2011-08-17 15:07:10

标签: python django session-variables django-haystack

我想在我的视图中保存用户输入,我不知道如何重新定义searchview,所以我这样做了:

  request.session['q']=request.GET.get('q')
  from haystack.views import SearchView
  search_view = SearchView(template = template_name)
  return search_view(request)

但是我收到了这个错误:

  Traceback (most recent call last):

   File "/home/usu/mysites/gondor/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 280, in run
    self.result = application(self.environ, self.start_response)

   File "/home/usu/mysites/gondor/local/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 674, in __call__
    return self.application(environ, start_response)

   File "/home/usu/mysites/gondor/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 245, in __call__
    response = middleware_method(request, response)

   File "/home/usu/mysites/gondor/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py", line 36, in process_response
    request.session.save()

   File "/home/usu/mysites/gondor/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py", line 57, in save
    session_data = self.encode(self._get_session(no_load=must_create)),

   File "/home/usu/mysites/gondor/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py", line 88, in encode
    pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)

   File "/usr/local/lib/python2.7/dist-packages/haystack/models.py", line 175, in __getstate__   del(ret_dict['searchsite'])

KeyError: 'searchsite'

如果我删除该行:

 request.session['q']=request.GET.get('q') 

搜索工作正常,我不知道干草堆是否存在问题,或者我做错了什么。 谢谢。

1 个答案:

答案 0 :(得分:0)

最后我发现了问题。在另一个视图中,我在会话中保存了一个SerchQuerySet的结果,但是当我放入内容时问题没有提出,但是当我把其他东西放在会话中时它就提出了。这很难找到。