from django import template
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.template import loader


@login_required(login_url="/login/")
def index(request):
    context = {}
    context["segment"] = "index"

    html_template = loader.get_template("index.html")
    return HttpResponse(html_template.render(context, request))


@login_required(login_url="/login/")
def pages(request):
    context = {}
    # All resource paths end in .html.
    # Pick out the html file name from the url. And load that template.
    try:
        load_template = request.path.split("/")[-1]
        context["segment"] = load_template
        html_template = loader.get_template(load_template)
        return HttpResponse(html_template.render(context, request))
    except template.TemplateDoesNotExist:
        html_template = loader.get_template("page-404.html")
        return HttpResponse(html_template.render(context, request))
    except:  # noqa: E722
        html_template = loader.get_template("page-500.html")
        return HttpResponse(html_template.render(context, request))

[((161, 196), 'django.contrib.auth.decorators.login_required', 'login_required', ([], {'login_url': '"""/login/"""'}), "(login_url='/login/')\n", (175, 196), False, 'from django.contrib.auth.decorators import login_required\n'), ((389, 424), 'django.contrib.auth.decorators.login_required', 'login_required', ([], {'login_url': '"""/login/"""'}), "(login_url='/login/')\n", (403, 424), False, 'from django.contrib.auth.decorators import login_required\n'), ((288, 321), 'django.template.loader.get_template', 'loader.get_template', (['"""index.html"""'], {}), "('index.html')\n", (307, 321), False, 'from django.template import loader\n'), ((701, 735), 'django.template.loader.get_template', 'loader.get_template', (['load_template'], {}), '(load_template)\n', (720, 735), False, 'from django.template import loader\n'), ((870, 906), 'django.template.loader.get_template', 'loader.get_template', (['"""page-404.html"""'], {}), "('page-404.html')\n", (889, 906), False, 'from django.template import loader\n'), ((1025, 1061), 'django.template.loader.get_template', 'loader.get_template', (['"""page-500.html"""'], {}), "('page-500.html')\n", (1044, 1061), False, 'from django.template import loader\n')]