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 ekosistem.models import *

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

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

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

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

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