I’m using PyCharm Pro (latest version). The code works correctly using 127.0.0.1:8000/polls/ and shows me each question in the dbase in the index.view. But when I select the question and the detail.view is executed I get this url, polls/polls/1/ as shown below. I’m completely stumped as to the why the index view works and the detail view doesn’t. I get the same message manually correcting the URL path to 127.0.0.1:8000/polls/1/ with the same result.
Request Method: GET Request URL: http://127.0.0.1:8000/polls/polls/1/ Using the URLconf defined in innotest.urls, Django tried these URL patterns, in this order:admin/
polls/ [name=‘index’]
polls/ int:question_id/ [name=‘detail’]
polls/ int:question_id/vote/ [name=‘vote’]
polls/ int:question_id/results/ [name=‘results’]
The current path, polls/polls/1/, didn’t match any of these.
Note: line spacing is compressed. (Actual code conforms to PEP 8)
<views.py>
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from .models import Question
# Create your views here.
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
# template = loader.get_template("polls/index.html")
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 = "You're looking at the results of %s" % question_id
return HttpResponse(response % question_id)
def vote(request, question_id):
return HttpResponse("You're voting on question %s." % question_id)
<polls/url.py>
app_name = 'polls'
urlpatterns = [
path("", views.index, name="index"),
path("int:question_id/", views.detail, name="detail"),
path("int:question_id/vote/", views.vote, name="vote"),
path("int:question_id/results/", views.results, name="results"),
]
I already don’t have any hair up top, so I’m doubly frustrated attempting to pull my hair out.
Thanks in advance for pointing out my fubar. I’m assuming since the default view works the other project files are correct at the top level.