added template

This commit is contained in:
Josh Flatt 2025-11-22 20:35:45 -06:00
parent 3da064e3af
commit f850f1f3e4
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,9 @@
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}

View File

@ -1,11 +1,17 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
from .models import Question
# Create your views here.
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
latest_question_list = Question.objects.order_by("-pub_date")[:5]
template = loader.get_template("polls/index.html")
context = {"latest_question_list": latest_question_list}
return HttpResponse(template.render(context, request))
def detail(request, question_id):