xxxxxxxxxx
# posts/views.py
from django.views.generic import ListView from .models import Post
class HomePageView(ListView):
model = Post
template_name = 'home.html'
context_object_name = 'all_posts_list' # change object_list name to
# anything
xxxxxxxxxx
from django.http import HttpResponse
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
xxxxxxxxxx
# views.py
from django.views.generic import ListView
from books.models import Publisher
class PublisherListView(ListView):
model = Publisher
xxxxxxxxxx
#Listview is usually a class that
#- generates context (among things)
#- or it takes a Model and generates a View (context) for a template
#- in Django
from django.views.generic import ListView
from myApp.models import myModel
class myListView(Listview)
model = myModel
#above two-liner basically creates a view from a model