django-ex/welcome/views.py
2020-09-30 17:39:09 +05:30

24 lines
768 B
Python

import os
from django.shortcuts import render
from django.conf import settings
from django.http import HttpResponse
from . import database
from .models import PageView
# Create your views here.
def index(request):
"""Takes an request object as a parameter and creates an pageview object then responds by rendering the index view."""
hostname = os.getenv('HOSTNAME', 'unknown')
PageView.objects.create(hostname=hostname)
return render(request, 'welcome/index.html', {
'hostname': hostname,
'database': database.info(),
'count': PageView.objects.count()
})
def health(request):
"""Takes an request as a parameter and gives the count of pageview objects as reponse"""
return HttpResponse(PageView.objects.count())