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
from django.http import HttpResponse #last line below allows MyView.get
# to return an HttpResponse object
from django.views import View #View is to become the parent class of MyView
class MyView(View):
''' View is the parent class that provides method as_view() to MyView '''
def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')
xxxxxxxxxx
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
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
from django.views import View
class MyView(View):
def get(self, request):
# <view logic>
return HttpResponse('result')
xxxxxxxxxx
# views.py
from django.views.generic import ListView
from books.models import Publisher
class PublisherListView(ListView):
model = Publisher