开发者

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

开发者 https://www.devze.com 2022-12-19 03:06 出处:网络
IndexError: list index out of range this is my django code : import os os.environ[\"DJANGO_SETTINGS_MODULE\"] = \"sphinx_test.settings\"

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开发者_StackOverflow 52, in __new__
    kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range


You need to set Meta.app_label to something usable.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号