Haystack-django SyntaxError: 'return' outside function
Question: **My 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
    

When i run in command prompt

**I am using Haystack with Whoosh**

**python .\manage.py rebuild_index**

**_Error_**

    
    
    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
    

I am doing a small web search project where we need data in json format

please help

I will be very thankful to you


Answer: Make sure you're not mixing spaces and tabs for indentation.

One possible reason for the error is that the line containing the `return`
statement is indented with tab, while other statements are indented with
spaces.

Choose spaces (preferred) or tab only for indentation.

