0
내 Search_Indexes건초 더미-장고 구문 에러 :. 함수 외부 '반환'
from datetime import datetime
from haystack import indexes
import json
from dezign.models import dezign
class dezignIndex(indexes.SearchIndex,indexes.Indexable):
text=indexes.CharField(document=True,use_template=True)
post_date=indexes.DateTimeField(model_attr='post_date')
like=indexes.IntegerField(model_attr='like',indexed=False)
#content_auto=indexes.EdgeNgramField(model_attr='title')
#r= indexes.CharField(indexed=False)
def get_model(self):
return dezign
def index_queryset(self,using=None):
return self.get_model().objects.filter(like__exact=0)
# Error in prepare method
def prepare(self, object):
self.prepared_data = super(dezignIndex, self).prepare(object)
self.dezign_jsonformat=[]
select_dezign = dezign.objects.filter(like=self.prepared_data['like'])
for i in select_dezign:
dezign_jsonformat.append({'title':i.title,'body':i.body,'like':i.like,'date':i.post_date})
self.prepared_data['list']=json.dumps(dezign_jsonformat)
return self.prepared_data
내가 붕
파이썬 함께 건초 더미를 사용하고
명령 프롬프트에서 실행 \ manage.py rebuild_index
오류
PS C:\Python27\Scripts\dezignup_django> python .\manage.py rebuild_index
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
Traceback (most recent call last):
File ".\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\haystack\management\commands\rebuild_index.py", line 15, in handle
call_command('clear_index', **options)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\haystack\management\commands\clear_index.py", line 50, in handle
backend.clear()
File "C:\Python27\lib\site-packages\haystack\backends\whoosh_backend.py", line 239, in clear
self.setup()
File "C:\Python27\lib\site-packages\haystack\backends\whoosh_backend.py", line 126, in setup
self.content_field_name, self.schema = self.build_schema(connections[self.connection_alias].get_unified_index().all_
searchfields())
File "C:\Python27\lib\site-packages\haystack\utils\loading.py", line 316, in all_searchfields
self.build()
File "C:\Python27\lib\site-packages\haystack\utils\loading.py", line 200, in build
indexes = self.collect_indexes()
File "C:\Python27\lib\site-packages\haystack\utils\loading.py", line 169, in collect_indexes
search_index_module = importlib.import_module("%s.search_indexes" % app)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\Python27\Scripts\dezignup_django\dezign\search_indexes.py", line 28
return self.prepared_data
SyntaxError: 'return' outside function
나는 우리가
도와주세요 JSON 형식의 데이터가 필요 작은 웹 검색 프로젝트를하고있는 중이 야
당신
들여 쓰기를 확인하십시오. 탭과 스페이스의 혼합? 그러지 마. – alecxe