玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容

django创建的blog出错:list index out of range 必须要有app

django创建的blog出错:list index out of range 必须要有app,原本是可以用的,博客是项目下的一个app。后来我把博客升级为项目,不再做为为项目下一个app,做了一些修改。出现了如下错误。所有页面都是类似错误。

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/

Django Version: 1.6.2
Python Version: 3.4.0
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py" in wrapper
  215.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/utils/decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py" in inner
  198.             return view(request, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/contrib/admin/sites.py" in index
  358.                             model_dict['admin_url'] = reverse('admin:%s_%s_changelist' % info, current_app=self.name)
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in reverse
  480.                 app_list = resolver.app_dict[ns]
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in app_dict
  310.             self._populate()
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in _populate
  285.                 lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in callback
  229.         self._callback = get_callable(self._callback_str)
File "/usr/local/lib/python3.4/dist-packages/django/utils/functional.py" in wrapper
  32.         result = func(*args)
File "/usr/local/lib/python3.4/dist-packages/django/core/urlresolvers.py" in get_callable
  96.             mod = import_module(mod_name)
File "/usr/lib/python3.4/importlib/__init__.py" in import_module
  109.     return _bootstrap._gcd_import(name[level:], package, level)
File "/home/caosz/ilemon/views.py" in <module>
  2. from models import Blog
File "/home/caosz/ilemon/models.py" in <module>
  4. class Tag(models.Model):
File "/usr/local/lib/python3.4/dist-packages/django/db/models/base.py" in __new__
  92.             kwargs = {"app_label": model_module.__name__.split('.')[-2]}

Exception Type: IndexError at /admin/
Exception Value: list index out of range

model.py如下:

from django.db import models

# Create your models here.
class Tag(models.Model):
    tag_name = models.CharField(max_length=20)
    create_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.tag_name

class Author(models.Model):
    name = models.CharField(max_length=30)
    email = models.EmailField()

    def __str__(self):
        return self.name

class Blog(models.Model):
    caption = models.CharField(max_length=50)
    author = models.ForeignKey(Author)
    tags = models.ManyToManyField(Tag, blank=True)
    content = models.TextField()
    publish_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.caption + str(self.author) + str(self.publish_time)

    class Meta:
        ordering = ['-publish_time']


经过查阅资料:
要使用model必须要有app,新建app里面可以没有url.py,这样不影响url简短

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/wenda/wd19701.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2018年03月07日 - 15时09分00秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules