Include database info in welcome page
This commit is contained in:
parent
00dccbbc31
commit
25e334bd69
2 changed files with 18 additions and 0 deletions
|
@ -51,6 +51,7 @@
|
||||||
<div id="hostname">
|
<div id="hostname">
|
||||||
<p>
|
<p>
|
||||||
Server hostname: {{ hostname }}<br>
|
Server hostname: {{ hostname }}<br>
|
||||||
|
Database server: {{ database_info }}<br>
|
||||||
Page views: {{ count }}
|
Page views: {{ count }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,14 +1,31 @@
|
||||||
import os
|
import os
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from .models import PageView
|
from .models import PageView
|
||||||
|
|
||||||
# Create your views here.
|
# 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):
|
def index(request):
|
||||||
hostname = os.getenv('HOSTNAME', 'unknown')
|
hostname = os.getenv('HOSTNAME', 'unknown')
|
||||||
PageView.objects.create(hostname=hostname)
|
PageView.objects.create(hostname=hostname)
|
||||||
|
|
||||||
return render(request, 'openshift/index.html', {
|
return render(request, 'openshift/index.html', {
|
||||||
'hostname': hostname,
|
'hostname': hostname,
|
||||||
|
'database_info': database_info,
|
||||||
'count': PageView.objects.count()
|
'count': PageView.objects.count()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue