【发布时间】:2018-10-24 08:04:37
【问题描述】:
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
我错过了什么?...
【问题讨论】:
-
你导入客户模型了吗?
-
是的,
from . import models