繁体   English   中英

Haystack-django SyntaxError:外部函数“返回”

[英]Haystack-django SyntaxError: 'return' outside function

我的搜索索引

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

当我在命令提示符下运行

我正在将草垛与Whoosh一起使用

python。\\ 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格式的数据

请帮忙

我会非常感谢你

确保您没有混合空格和制表符来缩进。

错误的可能原因之一是,包含return语句的行以tab缩进,而其他语句则以空格缩进。

选择空格(首选)或制表符仅用于缩进。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM