from django.shortcuts import render, render_to_response
from django.http.response import HttpResponseRedirect, HttpResponse
from django.template import loader
from django.template.context import RequestContext

# Create your views here.
def main(request):
    return render_to_response('main.html')
    
def setos(request):
    #print('setos')
    if "favorite_os" in request.GET:
        request.session['f_os'] = request.GET['favorite_os']
        return HttpResponseRedirect('/showos')
    else:
        return render_to_response('setos.html')
    
def showos(request):
    context = {}
    if 'f_os' in request.session:
        context['f_os'] = request.session['f_os']
        context['message'] = '선택하신 운영체제는 %s'%request.session['f_os']
    else:
        context['f_os'] = None
        context['message'] = '운영체제를 선택하세요'
        
    template = loader.get_template('showos.html')
    data = RequestContext(request, context)
    request.session.set_expiry(5)
    return HttpResponse(template.render(data), request)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    