added template
This commit is contained in:
parent
3da064e3af
commit
f850f1f3e4
9
polls/templates/polls/index.html
Normal file
9
polls/templates/polls/index.html
Normal 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 %}
|
||||||
@ -1,11 +1,17 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.template import loader
|
||||||
|
|
||||||
|
from .models import Question
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
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):
|
def detail(request, question_id):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user