diff --git a/djlearn/polls/templates/polls/detail.html b/djlearn/polls/templates/polls/detail.html
new file mode 100644
index 0000000..4e1bd67
--- /dev/null
+++ b/djlearn/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/djlearn/polls/templates/polls/index.html b/djlearn/polls/templates/polls/index.html
new file mode 100644
index 0000000..4560139
--- /dev/null
+++ b/djlearn/polls/templates/polls/index.html
@@ -0,0 +1,9 @@
+{% if latest_question_list %}
+
+{% else %}
+ No polls are available.
+{% endif %}
diff --git a/djlearn/polls/urls.py b/djlearn/polls/urls.py
index 9a62f74..1e61ab4 100644
--- a/djlearn/polls/urls.py
+++ b/djlearn/polls/urls.py
@@ -1,6 +1,10 @@
from django.urls import path
from . import views
+app_name = 'polls'
urlpatterns = [
- path("", views.index, name="index")
+ 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/djlearn/polls/views.py b/djlearn/polls/views.py
index 18923c8..9d42a1c 100644
--- a/djlearn/polls/views.py
+++ b/djlearn/polls/views.py
@@ -1,8 +1,25 @@
-from django.shortcuts import render
+from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
+from .models import Question
# Create your views here.
def index(request):
- return HttpResponse("Hello World. This is the Polls index")
+ latest_question_list = Question.objects.order_by('-pub_date')[:5]
+ context = {'latest_question_list': latest_question_list}
+ return render(request, 'polls/index.html', context)
+
+
+def detail(request, question_id):
+ question = get_object_or_404(Question, pk=question_id)
+ return render(request, 'polls/detail.html', {'question': question})
+
+
+def results(request, question_id):
+ response = f"You're looking @ the results of question {question_id}"
+ return HttpResponse(response)
+
+
+def vote(request, question_id):
+ return HttpResponse(f"You're voting on question {question_id}")