IndexError:列表索引超出范围
这是我的django代码:
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'
和
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
设置为可用的值。
关于python - 为什么在我的Django代码中“列表索引超出范围”;,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2211705/