如何让django-ezviews启动并运行

时间:2014-12-19 19:03:11

标签: python django django-views

我无法理解如何让django-ezviews正常工作。我在views.py文件中有一个基于类的视图,但它不会从我的模型或渲染中返回任何数据。我一直收到错误:type object 'datatablesTestView' has no attribute 'asView'

Models.py

class IPED(models.Model):
    unitid = models.IntegerField(unique=True)
    instnm = models.CharField(max_length=300)
    addr = models.CharField(max_length=500)
    city = models.CharField(max_length=120)
    state = models.CharField(max_length=3)
    zipcode = models.IntegerField(default=0)
    census = models.CharField(max_length=120)

views.py

class datatablesTestView(DatatablesView):
    model = IPED

    fields = (
        'unitid',
        'instnm',
        'city',
        'state',
        'census',
    )

urls.py

from tracker_app.views import datatablesTestView

urlpatterns = patterns('',
    url(r'^$', 'tracker_app.views.index', name='index'),
    url(r'^test/$', datatablesTestView.asView(),name="datatables test"),
)

1 个答案:

答案 0 :(得分:0)

Python使用snake_case来命名事物,而不是camelCase,以及PEP8中指出的其他内容。

您正在呼叫asView,但您应该真正致电as_view