Add page view counter
To showcase database connectivity.
This commit is contained in:
parent
d398a46623
commit
86f8f20776
4 changed files with 35 additions and 2 deletions
21
openshift/migrations/0001_initial.py
Normal file
21
openshift/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PageView',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
|
||||
('hostname', models.CharField(max_length=32)),
|
||||
('timestamp', models.DateTimeField(auto_now_add=True)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1,3 +1,7 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class PageView(models.Model):
|
||||
hostname = models.CharField(max_length=32)
|
||||
timestamp = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
@ -50,7 +50,8 @@
|
|||
|
||||
<div id="hostname">
|
||||
<p>
|
||||
Server hostname: {{ HOSTNAME }}
|
||||
Server hostname: {{ HOSTNAME }}<br>
|
||||
Page views: {{ count }}
|
||||
</p>
|
||||
</div>
|
||||
</body></html>
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
import os
|
||||
from django.shortcuts import render
|
||||
|
||||
from .models import PageView
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def index(request):
|
||||
return render(request, 'openshift/index.html', {'HOSTNAME': os.getenv('HOSTNAME', 'unknown')})
|
||||
hostname = os.getenv('HOSTNAME', 'unknown')
|
||||
PageView.objects.create(hostname=hostname)
|
||||
return render(request, 'openshift/index.html', {
|
||||
'HOSTNAME': hostname,
|
||||
'count': PageView.objects.count()
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue