我试图编写一个 DetailView 来使用模型中的一个字段template_name
,我可以在其中指定每个条目的模板名称(如平面模型)。我正在尝试使用 DetailView,但也许我不应该使用它?
这是我尝试编写的内容,但出现此错误:'NoneType' object has no attribute 'render'
class EntryDetailView(DetailView):
model = Entry
def get_template_names(Entry, **kwargs):
if Entry.template_name:
template_name = "entry/%s" % Entry.template_name
else:
template_name = "entry/entry_detail.html"
关于如何正确处理的任何提示?
编辑:
这是我的回溯:
Traceback:
File "/home/USER/.virtualenvs/PROJECT/src/Django-1.6b2/django/core/handlers/base.py" in get_response
139. response = response.render()
File "/home/USER/.virtualenvs/PROJECT/src/Django-1.6b2/django/template/response.py" in render
105. self.content = self.rendered_content
File "/home/USER/.virtualenvs/PROJECT/src/Django-1.6b2/django/template/response.py" in rendered_content
82. content = template.render(context)
Exception Type: AttributeError at /entries/test/
Exception Value: 'NoneType' object has no attribute 'render'