I’m following the Django tutorial as a first time user, but I’m getting stuck at [part 3](https://docs.djangoproject.com/en/3.2/intro/tutorial03/)
.
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 polls/views.py
.
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 polls.urls
module
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.
The 3rd step does not work, when I enter http://localhost:8000/polls/34/ (while running the server), I get a 404 error. I also tried http://127.0.0.1:8000/34/.
Can somebody help me out?