我在我的Ubuntu服务器上使用django-haystack和elasticsearch,发现某些搜索查询只会引发错误页面,我不知道为什么会这样。 任何帮助赞赏! :)
model.py:
class EnActress(models.Model):
name = models.CharField(max_length=100, null=True)
image_urls = models.CharField(max_length=200)
images = models.TextField(null=True)
actress_image = models.TextField(null=True)
class EnMovielist(models.Model):
content_ID = models.CharField(max_length=30)
release_date = models.CharField(max_length=30)
running_time = models.CharField(max_length=10)
actress = models.CharField(max_length=300)
series = models.CharField(max_length=30)
director = models.CharField(max_length=30)
label = models.CharField(max_length=30)
image_urls = models.CharField(max_length=200, null=True)
images = models.TextField(null=True)
image_paths = models.TextField(null=True)
search.indexes.py:
class EnActressIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
en_name = indexes.CharField(model_attr='name')
def get_model(self):
return EnActress
def index_queryset(self, using=None):
return self.get_model().objects.all()
class EnMovielistIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
content_ID = indexes.CharField(model_attr='content_ID')
release_date = indexes.CharField(model_attr='release_date')
actress = indexes.CharField(model_attr='actress')
label = indexes.CharField(model_attr='label')
def get_model(self):
return EnMovielist
def index_queryset(self, using=None):
return self.get_model().objects.all()
这是Django的错误按摩
VariableDoesNotExist at /search/
Failed lookup for key [actress_image] in 'EnMovielist object'
Failed lookup for key [%s] in %r
In template /home/ubuntu/venv/avdict/dmmactress/templates/search/search.html, error at line 122
112 {% load staticfiles %}
113 <table class="table table-striped table-hover" cellspacing="0" id='result_table'>
114 <thead>
115 <tr>
116 <th>phto</th>
117 <th>name</th>
118 </tr>
119 </thead>
120 <tbody>
121 <tr class="active">
122 {% with image='enActress/'|add:result.object.actress_image %}
123 <td><img src="{% static image %}" class="img-circle" class="img-responsive" alt="{{result.object.name}}"></td>
124 <td>{{ result.object.name }}</td>
125 {% endwith %}
126 </tr>
127
128 </tbody>
129 </table>
130 {% empty %}
131 <p>no results.</p>
132 {% endfor %}
enactress_text.txt file :
{{ object.name}}
{{ object.actress_image }}
enmovielist_text.txt file :
{{ object.content_ID }}
{{ object.image_paths }}
{{ object.release_date }}
{{ object.running_time }}
{{ object.actress }}
{{ object.series }}
{{ object.director }}
{{ object.label }}
答案 0 :(得分:0)
Failed lookup for key [actress_image] in 'EnMovielist object'
这意味着您正在查找actress_image
对象的EnMovielist
值。
您可能尝试做的事情需要result.object
成为EnActress
的实例。