from django.shortcuts import render from django.http import HttpResponse # Import models that we need to use from .models import ClickCount # Create your views here. def index_view(request): # Get the number of clicks from the database click_count = ClickCount.objects.first() # If the click_count is None, then we have not yet clicked if click_count is None: click_count = ClickCount(1) click_count.save() # Increment the click count click_count.clicks += 1 click_count.save() # When this view is requested we will respond with this text text = "Hello World! This is the testapp.
This page was requested " + str(click_count.clicks) + " times." # Build a Http response with our text and send it to the requester return HttpResponse(text)