I’m following the Django tutorial as a first time user, but I’m getting stuck at
I believe the goal of the tutorial is to input a value into the address bar, like poll/34/, which will run a method found in the view.py. The following steps (included my code) are:
1. add a few more views to
from django.shortcuts import render from django.http import HttpResponse def index(request): return HttpResponse("Hello, world. You're at the polls index.") def detail(request, question_id): return HttpResponse("You're looking at question %s." % question_id) def results(request, question_id): response = "You're looking at the results of question %s." return HttpResponse(response % question_id) def vote(request, question_id): return HttpResponse("You're voting on question %s." % question_id)
2. I Wire these new views into the
from django.urls import path from . import views urlpatterns = [ # ex: /polls/ path('', views.index, name='index'), # ex: /polls/5/ path('<int:question_id>/', views.detail, name='detail'), # ex: /polls/5/results/ path('<int:question_id>/results/', views.results, name='results'), # ex: /polls/5/vote/ path('<int:question_id>/vote/', views.vote, name='vote'), ]
3. Take a look in your browser, at “/polls/34/”. It’ll run the
detail() method and display whatever ID you provide in the URL.
Can somebody help me out?