名称'Customer'未定义CBV ListView

时间:2018-05-14 15:34:23

标签: python django

urls.py

from django.conf.urls import url
from system import views

app_name = 'project'

urlpatterns = [
    ...
    url(r'^cust/([\w-]+)/$',views.PublisherBookList.as_view()),
    ...
]

views.py

from . import models

class PublisherBookList(ListView):

    def get_queryset(self):
        self.name = get_object_or_404(Customer, name=self.args[0])
        return Customer.objects.filter(name=self.name)

models.py

class Customer(models.Model):
    name = models.CharField(max_length=255)

我确实访问了http://127.0.0.1:8000/project/custo/customername/

收到错误name 'Customer' is not defined

我错过了什么?...

1 个答案:

答案 0 :(得分:2)

您需要在views.py

中导入客户
from .models import Customer