from django.contrib.auth import logout
from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader
from django.shortcuts import redirect
from django.urls import reverse


def index(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect(reverse('bills:index'))
    # return HttpResponse("Hi there! This is the API index")
    else:
        template = loader.get_template('index.html')
        context = {}
        return HttpResponse(template.render(context, request))


def logout(request):
    logout(request)
    redirect(index)
