Django-Haystack给出属性错误? [英] Django-Haystack giving attribute error?

查看:299
本文介绍了Django-Haystack给出属性错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用我的Django应用程序使用Haystack和Whoosh。我按照Haystack文档中的步骤,但是当我进行搜索时,我收到此错误。

  / search / $ b中的AttributeError $ b'module'对象没有属性'get_model'

search_indexes.py -

  import datetime 
from haystack import indexes
from movies.models import电影


class MovieIndex(indexes.SearchIndex,indexes.Indexable):
text = indexes.CharField(document = True,use_template = True)
title = indexes.CharField(model_attr ='title')

def get_model(self):
return Movie

def index_queryset(self,using = None):
当模型的整个索引为更新。
return self.get_model()。objects.all()

我找不到任何地方这个错误的帮助,我做错了什么?



Stacktrace -

 环境:


Reque st方法:GET
请求URL:http://127.0.0.1:8000/search/?q=The+Revenant&models=movies.movi​​e

Django版本:1.9.1
Python版本:2.7.6
已安装的应用程序:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib。 contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'whoosh',
'haystack',
'registration',
'crispy_forms',
'movies',
'mptt')
安装的中间件:
(' django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth。中间件.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.X
'django.middleware.security.SecurityMiddleware'



追溯:

文件/ home / dr_sherlock / get_response
中的movienalyse / virmovienalyse / local / lib / python2.7 / site-packages / django / core / handlers / base.py149. response = self.process_exception_by_middleware(e,request)

文件/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/django/core/handlers/base.pyin get_response
147. response = wrapped_callback(request,* callback_args,** callback_kwargs)

文件/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/views.py在__call__
51 。self.results = self.get_results()

文件/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/views.pyin get_results
91. return self.form.search()

文件/ home / dr_sherlock / movienalys e / virmovienalyse / local / lib / python2.7 / site-packages / haystack / forms.pyin search
116. return sqs.models(* self.get_models())

文件/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/forms.pyin get_models
110. search_models.append(models.get_model(* model.split( '')))

异常类型:/ search /
中的AttributeError异常值:'module'对象没有属性'get_model'

Python 2.7.6

Django 1.9.1

干草堆2.4.1

Whoosh 2.7.0

解决方案

这看起来像是Haystack和Django版本之间的兼容性问题。 Django最近修改了 get_model 系统(我认为在1.9),所以如果你已经升级了Django而不是Haystack,或者反之亦然,这可能是问题。 / p>

我猜想你的索引文件中的 get_model()引用是一个潜在的红色鲱鱼,问题是在干草堆内部的内部,因为它不能找到它期望的方法。


I am trying to use Haystack and Whoosh with my Django app. I followed the steps on Haystack docs, but i am getting this error when i do a search

AttributeError at /search/
'module' object has no attribute 'get_model'

search_indexes.py -

import datetime
from haystack import indexes
from movies.models import Movie


class MovieIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')

    def get_model(self):
        return Movie

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()

I couldn't find help on this error anywhere, what am i doing wrong?

Stacktrace -

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/search/?q=The+Revenant&models=movies.movie

Django Version: 1.9.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'whoosh',
 'haystack',
 'registration',
 'crispy_forms',
 'movies',
 'mptt')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')



Traceback:

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/views.py" in __call__
  51.         self.results = self.get_results()

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/views.py" in get_results
  91.         return self.form.search()

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/forms.py" in search
  116.         return sqs.models(*self.get_models())

File "/home/dr_sherlock/movienalyse/virmovienalyse/local/lib/python2.7/site-packages/haystack/forms.py" in get_models
  110.                 search_models.append(models.get_model(*model.split('.')))

Exception Type: AttributeError at /search/
Exception Value: 'module' object has no attribute 'get_model'

Python 2.7.6
Django 1.9.1
Haystack 2.4.1
Whoosh 2.7.0

解决方案

That looks to me like a compatibility issue between the version of Haystack and Django. Django recently reworked the get_model system (I think in 1.9), so if you've upgraded Django and not Haystack - or perhaps vice-versa - that may be the issue.

I'm guessing the get_model() references in your index file are a potential red-herring, and that the issue is within the Haystack internals, as it's not able to find that method where it expects to.

这篇关于Django-Haystack给出属性错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆