django-ex/welcome/views.py

32 lines
788 B
Python
Raw Normal View History

2015-05-24 13:56:43 +02:00
import os
2015-05-24 13:10:47 +02:00
from django.shortcuts import render
2015-05-25 20:57:28 +02:00
from django.conf import settings
2015-05-24 13:10:47 +02:00
from .models import PageView
2015-05-24 13:10:47 +02:00
# Create your views here.
2015-05-25 20:57:28 +02:00
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()
2015-05-24 13:10:47 +02:00
def index(request):
hostname = os.getenv('HOSTNAME', 'unknown')
PageView.objects.create(hostname=hostname)
2015-05-25 20:57:28 +02:00
2015-05-29 12:23:59 +02:00
return render(request, 'welcome/index.html', {
2015-05-25 20:54:23 +02:00
'hostname': hostname,
2015-05-25 20:57:28 +02:00
'database_info': database_info,
'count': PageView.objects.count()
})