from django.contrib.auth.decorators import login_required
from django.shortcuts import render, get_object_or_404, redirect
from django.template import loader
from django.http import HttpResponse
from django import template
from artikel.models import *

#@login_required(login_url="/login/")

def indexView(request):  
    context = {}
    context['segment'] = 'index'
    context['judul'] = 'Artikel'
    context['kata'] = 'INI ARTIKELnya'

    html_template = loader.get_template( 'artikel/index.html' )
    return HttpResponse(html_template.render(context, request))

def konten_detail(request, slug=None):
    context = {}
    context['segment'] = 'index'
    context['judul'] = 'Artikel'

    konten_obj = None
    if slug is not None:
        try:
            konten_obj = Konten.objects.get(slug=slug)
        except Konten.DoesNotExist:
            raise Http404
        except Konten.MultipleObjectsReturned:
            article_obj = Article.objects.filter(slug=slug).first()
        except:
            raise Http404
    context = {
        "object": konten_obj,
    }
    #return render(request, "artikel/detail.html", context=context)
    
    html_template = loader.get_template( 'artikel/detail.html' )
    return HttpResponse(html_template.render(context, request))