3
我正在学习Django,并且我在网上找到了一个非常基本的示例,介绍如何使用模板显示表。我跟着的代码完全,但出于某种原因,我得到的错误:为什么我会收到错误:“错误:Render_to_response未定义”; Django
Error: Render_to_response not defined
这里是我的views.py:
from django.shortcuts import render
def display(request):
return render_to_response('template.tmpl', {'obj':models.Book.objects.all()})
这里是我的urls.py:
这里是我的template.tmpl:
<table>
<tr>
<th>author</th>
<th>title</th>
<th>publication year</th>
</tr>
{% for b in obj %}
<tr>
<td>{{ b.author }}</td>
<td>{{ b.title }}</td>
<td>{{ b.publication_year }}</td>
</tr>
{% endfor %}
</table>
这里我我的models.py:
from django.db import models
class Book(models.Model):
author = models.CharField(max_length = 20)
title = models.CharField(max_length = 40)
publication_year = models.IntegerField()
我在网上找了一些帮助,这错误,但所有的问题似乎要比我面对一个更加复杂。有什么我失踪?
哇...这是非常简单的。非常感谢! –
也许接受答案? :) –
是的,我现在可以做到。它让我等了几分钟。感谢提醒和答案! :) –