简体   繁体   中英

why 'list index out of range' in my django code;

IndexError: list index out of range

this is my django code :

import os
os.environ["DJANGO_SETTINGS_MODULE"] = "sphinx_test.settings"

#from django.core.management import setup_environ
#from sphinx_test import settings

#setup_environ(settings)


from django.db import models
from djangosphinx.models import SphinxSearch,SphinxQuerySet




class File(models.Model):
    name = models.CharField(max_length=200)
    tags = models.CharField(max_length=200) 

    objects = models.Manager()
    search  = SphinxQuerySet(index="test1")


import datetime



class Group(models.Model):
    name = models.CharField(max_length=32)

class Document(models.Model):
    group       = models.ForeignKey(Group)
    date_added  = models.DateTimeField(default=datetime.datetime.now)
    title       = models.CharField(max_length=32)
    content     = models.TextField()

    search      = SphinxQuerySet(File,index="test1")

    class Meta:
        db_table = 'documents'

and

Traceback (most recent call last):
  File "D:\zjm_code\sphinx_test\models.py", line 16, in <module>
    class File(models.Model):
  File "D:\Python25\Lib\site-packages\django\db\models\base.py", line 52, in __new__
    kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range

您需要将Meta.app_label设置为可用的东西。

That's odd, that part of the code is just supposed to determine your app name. See the section here starting line 45. What's your app name for this?

You may be able to avoid the error by setting app_label to the name of your app in the Meta section of your model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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