Fakultas Ilmu Komputer UI

views.py 1009 Bytes
Newer Older
Samuel Dimas's avatar
Samuel Dimas committed
1
2
3
from django.shortcuts import render, get_object_or_404, redirect
from django.template import loader
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
4
5
6
from django.views.generic import TemplateView 

class DaftarKatalog(TemplateView):
7
8
9
10
11
12
13
14
    template_name = "app/katalog_materi.html"

    def get_context_data(self, **kwargs):
        return super().get_context_data(**kwargs)

    def get(self, request, *args, **kwargs):
        context = self.get_context_data(**kwargs)
        return self.render_to_response(context=context)
Samuel Dimas's avatar
Samuel Dimas committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

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]
        template = loader.get_template(load_template)
        return HttpResponse(template.render(context, request))

    except:

        template = loader.get_template('error-404.html')
        return HttpResponse(template.render(context, request))