我正在尝试使用django-nested-inline包。看起来一切正常但是当我尝试使用管理员网站创建新的Course
时,我收到以下错误:
TemplateDoesNotExist at /admin/courses/course/5/
admin/edit_inline/stacked-nested.html
但当然,admin/edit_inline/stacked-nested.html
只是不存在,因为模板渲染过程中出现错误:
Error during template rendering
In template C:\...\django\contrib\admin\templates\admin\change_form.html, error at line 62
admin/edit_inline/stacked-nested.html
60 {% block inline_field_sets %}
61 {% for inline_admin_formset in inline_admin_formsets %}
62 {% include inline_admin_formset.opts.template %}
63 {% endfor %}
64 {% endblock %}
正如你所看到的,当Django试图渲染时,有些东西会混乱
{% include inline_admin_formset.opts.template %}
这是我的admin.py
,但我认为它与上述错误无关:
from django.contrib import admin
from nested_inline.admin import NestedStackedInline, NestedModelAdmin
from courses.models import Course, Skill, Note
class NoteInline(NestedStackedInline):
model = Note
extra = 0
class SkillInline(NestedStackedInline):
model = Skill
extra = 0
inlines = [NoteInline]
class CourseAdmin(NestedModelAdmin):
inlines = [SkillInline]
admin.site.register(Course, CourseAdmin)
这是我的models.py
:
from django.db import models
class Course(models.Model):
course_name = models.CharField(max_length=200)
course_description = models.CharField(max_length=1000, default='Course Description')
course_subject = models.CharField(max_length=200, default='No Subject')
def num_skills(self):
return len(self.skill_set.all())
def __unicode__(self):
return self.course_name
def __str__(self):
return unicode(self).encode('utf-8')
class Skill(models.Model):
course = models.ForeignKey(Course)
skill_name = models.CharField(max_length=200)
skill_description = models.CharField(max_length=1000, default='Skill Description')
def __unicode__(self):
return self.skill_name
def __str__(self):
return unicode(self).encode('utf-8')
class Note(models.Model):
skill = models.ForeignKey(Skill)
note_text = models.CharField(max_length=1000, default='...note text...')
def __unicode__(self):
return self.note_text
def __str__(self):
return unicode(self).encode('utf-8')
Course
时,管理网站和网站本身不会崩溃。答案 0 :(得分:3)
看起来你的nested_inline应用程序没有安装,或者django能够找到模板。 或者将模板添加到TEMPLATE_DIRS设置引用的目录中,或者更改内联的模板名称。
根据您提供的链接中的用法:将nested_inline添加到INSTALLED_APPS