1. Writing more views
polls/views.py
def detail(request, questionId):
return HttpResponse(f'You\'re looking at question {questionId}')
def results(request, questionId):
return HttpResponse(f'You\'re looking at the results of question {questionId}')
def vote(request, questionId):
return HttpResponse(f'You\'re voting on question {questionId}')
Wire these new views into the polls.urls
module by adding the following path()
calls:
polls/urls.py
urlpatterns = [
path('', views.index, name='index'),
path('<int:questionId>/', views.detail, name='detail'),
path('<int:questionId>/results', views.results, name='results'),
path('<int:questionId>/vote/', views.vote, name='vote'),
]
Visit http://127.0.0.1:8000/polls/12
with the web browser. It'll run the detail()
method and display a sentence: "You're looking at question 12". Try /polls/34/results/
and /polls/34/vote/
will display the placeholder results and voting pages.