diff --git a/django/mysite/polls/templates/polls/detail.html b/django/mysite/polls/templates/polls/detail.html
new file mode 100644
index 0000000..e38ffba
--- /dev/null
+++ b/django/mysite/polls/templates/polls/detail.html
@@ -0,0 +1,6 @@
+
{{ question.question_text }}
+
+ {% for choice in question.choice_set.all %}
+ - {{ choice.choice_text }}
+ {% endfor %}
+
\ No newline at end of file
diff --git a/django/mysite/polls/templates/polls/index.html b/django/mysite/polls/templates/polls/index.html
new file mode 100644
index 0000000..8f6b1b3
--- /dev/null
+++ b/django/mysite/polls/templates/polls/index.html
@@ -0,0 +1,9 @@
+{% if latest_questions %}
+
+{% else %}
+ No polls are available.
+{% endif %}
\ No newline at end of file
diff --git a/django/mysite/polls/urls.py b/django/mysite/polls/urls.py
index 88a9cac..293729b 100644
--- a/django/mysite/polls/urls.py
+++ b/django/mysite/polls/urls.py
@@ -2,6 +2,10 @@ from django.urls import path
from . import views
+app_name = 'polls'
urlpatterns = [
path('', views.index, name='index'),
+ path('/', views.detail, name='detail'),
+ path('/results/', views.results, name='results'),
+ path('/vote/', views.vote, name='vote'),
]
diff --git a/django/mysite/polls/views.py b/django/mysite/polls/views.py
index 34c2c6b..4ae3f90 100644
--- a/django/mysite/polls/views.py
+++ b/django/mysite/polls/views.py
@@ -1,6 +1,23 @@
-from django.shortcuts import render
-from django.http import HttpResponse
+from django.http import HttpResponse, Http404
+from django.shortcuts import get_object_or_404, render
+
+from . import models
+
# Create your views here.
def index(request):
- return HttpResponse("Hello, world. You're at the polls index.")
+ latest_questions = models.Question.objects.order_by('-pub_date')[:5]
+ ctx = {'latest_questions': latest_questions}
+ return render(request, 'polls/index.html', ctx)
+
+def detail(request, question_id):
+ q = get_object_or_404(models.Question, pk=question_id)
+ return render(request, 'polls/detail.html', {'question': q})
+
+def results(request, question_id):
+ response = "Tally for \"{}\":".format(question_id)
+ return HttpResponse(response)
+
+def vote(request, question_id):
+ return HttpResponse("You're voting on {}".format(question_id))
+