django之ListView的简单用法

2015-06-19, 星期五 |
Djangotutorial

Django的built-in Class-based-view中有一个是ListView,它在 django.views.generic.list 中, 它的具体用法参见Django documentation后发现有几个文件需要修改。

  • app/views.py
  • app/urls.py
  • app/templates/app/modelname_list.html

修改views.py

#app/views.py
from .models import Article
from django.views.generic.list import ListView

class ArticleListView(ListView):
    model = Article
    #template_name = "article_list.html"

修改urls.py

#app/urls.py
from django.conf.urls import url, patterns, include
from .views import ArticleListView

urlpatte