from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from django.http import Http404
from .models import *


def index(request):
    latest_questions = Question.objects.order_by('-pub_date')#[:2]
    context = {
        'latest_questions': latest_questions
    }
    return render(request, 'app1/index.html', context)


def detail(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    return render(request, 'app1/detail.html', {'question': question})


def results(request, question_id):
    response = 'You\'re looking at the results for question %s'
    return HttpResponse(response % question_id)


def vote(request):
    pass
