Include database info in welcome page

This commit is contained in:
Rodolfo Carvalho 2015-05-25 20:57:28 +02:00
parent 00dccbbc31
commit 25e334bd69
2 changed files with 18 additions and 0 deletions

View file

@ -51,6 +51,7 @@
<div id="hostname">
<p>
Server hostname: {{ hostname }}<br>
Database server: {{ database_info }}<br>
Page views: {{ count }}
</p>
</div>

View file

@ -1,14 +1,31 @@
import os
from django.shortcuts import render
from django.conf import settings
from .models import PageView
# Create your views here.
def _database_info():
db_settings = settings.DATABASES['default']
if 'postgres' in db_settings['ENGINE']:
engine = 'PostgreSQL'
info = '{HOST}:{PORT}/{NAME}'.format(**db_settings)
else:
engine = 'SQLite'
info = '{NAME}'.format(**db_settings)
return '{} ({})'.format(engine, info)
database_info = _database_info()
def index(request):
hostname = os.getenv('HOSTNAME', 'unknown')
PageView.objects.create(hostname=hostname)
return render(request, 'openshift/index.html', {
'hostname': hostname,
'database_info': database_info,
'count': PageView.objects.count()
})