Why am I getting the following error: NameError: name 'models' is not defined
<p>Whenever I run the program, I get the following error:</p>

<pre><code>NameError at /table/
name 'models' is not defined
</code></pre>

<p>It says that there's an error on line 4 in my views. </p>

<p>Here is my views.py:</p>

<pre><code>from django.shortcuts import render

def display(request):
    return render(request, 'template.tmpl', {'obj': models.Book.objects.all()})
</code></pre>

<p>Here is my models.py:</p>

<pre><code>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()
</code></pre>

<p>Here is my urls.py:</p>

<pre><code>from django.conf.urls import url
from . import views

urlpatterns = [
    # /table/
    url(r'^$', views.display, name='display'),
]
</code></pre>

<p>Can somebody please tell me what is wrong?</p>

<p>You are referencing <code>models.Book</code> in your view, but you have not imported <code>models</code>. In your views.py you need to do <code>from myapp import models</code>. Or you can do <code>from myapp.models import Book</code> and change it in your view function to just <code>Book.objects.all()</code>.</p>

python django