Use html template to generate testapp views
This commit is contained in:
parent
165b34d74a
commit
d372de4d91
15
testapp/templates/testapp/index.html
Normal file
15
testapp/templates/testapp/index.html
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Testapp</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Testapp</h1>
|
||||||
|
<p>This is the testapp.</p>
|
||||||
|
{% if click_count %}
|
||||||
|
<p>This page was requested {{ click_count }} times.</p>
|
||||||
|
{% else %}
|
||||||
|
<p>Error: Could not get request count from database.</p>
|
||||||
|
{% endif %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -14,7 +14,10 @@ def index_view(request):
|
|||||||
# Increment the click count
|
# Increment the click count
|
||||||
click_count.clicks += 1
|
click_count.clicks += 1
|
||||||
click_count.save()
|
click_count.save()
|
||||||
# When this view is requested we will respond with this text
|
|
||||||
text = "Hello World! This is the testapp.<br>This page was requested " + str(click_count.clicks) + " times."
|
# This is a dictionary that will be passed to the template
|
||||||
# Build a Http response with our text and send it to the requester
|
# We will use it to pass the number of clicks to the template
|
||||||
return HttpResponse(text)
|
context = {'click_count': click_count.clicks}
|
||||||
|
|
||||||
|
# Render the template and return the response
|
||||||
|
return render(request, 'testapp/index.html', context)
|
||||||
Loading…
x
Reference in New Issue
Block a user