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
答案 0 :(得分:3)
您需要将Meta.app_label
设置为可用的内容。
答案 1 :(得分:1)
奇怪的是,这部分代码只是为了确定你的应用名称。请参阅here第一行第45节。您的应用名称是什么?
您可以通过在模型的Meta部分中将app_label设置为应用名称来避免错误。