每当我运行程序时,都会出现以下错误:
OperationalError at /table/
no such table: table_book
它说我的模板文件第7行出现错误。
这是我的template.html:
<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>
这是我的views.py:
from django.shortcuts import render
def display(request):
return render(request, 'template.tmpl', {'obj': models.Book.objects.all()})
这是我的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()
这是我的urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
# /table/
url(r'^$', views.display, name='display'),
]
有人可以告诉我出了什么问题吗?
答案 0 :(得分:0)
缺少数据库表table_book。你有没有运行makemigrations并迁移?