django博客:list index out of range
用django做博客,原本是可以用的,博客是项目下的一个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']
update:答案在这里。
http://stackoverflow.com/questions/4382032/defining-a-model-class-in-django-shell-fails
经过查阅资料:
要使用model必须要有app,新建app里面可以没有url.py,这样不影响url简短
蔓子的菊花
11 years ago
Answers
答案在这里。
http://stackoverflow.com/questions/4382032/defining-a-model-class-in-django-shell-fails
经过查阅资料:
要使用model必须要有app,新建app里面可以没有url.py,这样不影响url简短
宫本蕾貝卡
answered 11 years ago