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))

[((7, 1, 7, 36), 'django.contrib.auth.decorators.login_required', 'login_required', (), '', False, 'from django.contrib.auth.decorators import login_required\n'), ((16, 1, 16, 36), 'django.contrib.auth.decorators.login_required', 'login_required', (), '', False, 'from django.contrib.auth.decorators import login_required\n'), ((12, 20, 12, 53), 'django.template.loader.get_template', 'loader.get_template', ({(12, 40, 12, 52): '"""index.html"""'}, {}), "('index.html')", False, 'from django.template import loader\n'), ((24, 24, 24, 58), 'django.template.loader.get_template', 'loader.get_template', ({(24, 44, 24, 57): 'load_template'}, {}), '(load_template)', False, 'from django.template import loader\n'), ((27, 24, 27, 60), 'django.template.loader.get_template', 'loader.get_template', ({(27, 44, 27, 59): '"""page-404.html"""'}, {}), "('page-404.html')", False, 'from django.template import loader\n'), ((30, 24, 30, 60), 'django.template.loader.get_template', 'loader.get_template', ({(30, 44, 30, 59): '"""page-500.html"""'}, {}), "('page-500.html')", False, 'from django.template import loader\n')]