Django.urls.exceptions.NoReverseMatch: Обратное соответствие для 'detail' с аргументами '('',)' не найдено

Почему появляется сообщение об ошибке? Я застрял в официальном учебнике Django, часть 5. Написание вашего первого приложения Django, часть 5. Я понимаю, что сообщение об ошибке есть, но я НЕ могу определить причину ошибки. И я не забыл выполнить python manage.py makemigrations и python manage.py migrate один раз после изменения кода. Вот команды и сообщения об ошибках (в conda Terminal)

Здесь index.html На polls\templates\polls\index.html

<!DOCTYPE html>
    <head>
        <meta charset="utf-8" />
        <title>My test page</title>
    </head>
    <body>
        <!-- 
            <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li> 
        -->
        <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>
    </body>
</html>

Здесь results.html На polls\templates\polls\results.html

<!DOCTYPE html>
    <head>
        <meta charset="utf-8" />
        <title>My test page</title>
    </head>
    <body>
        <p>This is my page</p>
        <h1>{{ question.question_text }}</h1>
        <ul>
        {% for choice in question.choice_set.all %}
            <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
        {% endfor %}
        </ul>
        <a href="{% url 'polls:detail' question.id %}">Vote again?</a>
    </body>
</html>

Здесь находится test.py В polls\tests.py

from django.test import TestCase

# Create your tests here.
import datetime

from django.test import TestCase
from django.utils import timezone

from .models import Question


class QuestionModelTests(TestCase):
    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() returns False for questions whose pub_date
        is in the future.
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertIs(future_question.was_published_recently(), False)

    def test_was_published_recently_with_old_question(self):
        """
        was_published_recently() returns False for questions whose pub_date
        is older than 1 day.
        """
        time = timezone.now() - datetime.timedelta(days=1, seconds=1)
        old_question = Question(pub_date=time)
        self.assertIs(old_question.was_published_recently(), False)


    def test_was_published_recently_with_recent_question(self):
        """
        was_published_recently() returns True for questions whose pub_date
        is within the last day.
        """
        time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59)
        recent_question = Question(pub_date=time)
        self.assertIs(recent_question.was_published_recently(), True)


from django.test.utils import setup_test_environment
# setup_test_environment()
from django.test import Client
# create an instance of the client for our use
client = Client()
# get a response from '/'
response = client.get("/")
# we should expect a 404 from that address; if you instead see an
# "Invalid HTTP_HOST header" error and a 400 response, you probably
 # omitted the setup_test_environment() call described earlier.
print(response.status_code)
# on the other hand we should expect to find something at '/polls/'
# we'll use 'reverse()' rather than a hardcoded URL
from django.urls import reverse
revindex = reverse("polls:index")
print("revindex:")
print(revindex)
response = client.get(revindex)
print("response:")
print(response.status_code)
print(response.content)
print(response.context["latest_question_list"])

Здесь находится urls.py В polls\urls.py

# availables url 
from django.urls import path

from . import views

app_name = "polls"
urlpatterns = [
    path("", views.index, name="index"),
    path("<int:question_id>/", views.detail, name="detail"),
    path("<int:question_id>/results/", views.results, name="results"),
    path("<int:question_id>/vote/", views.vote, name="vote"),
    path("specifics/<int:question_id>/", views.detail, name="detail"),
]

Здесь находится polls.py На mysite\urls.py

"""mysite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path

app_name = "polls"

urlpatterns = [
    path("polls/", include("polls.urls")),
    path("admin/", admin.site.urls),
]

Здесь находится файл setting.py В mysite\settings.py

Вот структура моего проекта. enter image description here Благодарность: Любые ответы или решение этого вопроса будут очень признательны. Большое спасибо.

Пытаясь решить эту проблему, я не только посетил Django: Reverse for 'detail' with arguments '('',)' and keyword arguments '{}' not found

но также я проверил учебник Django Official с части 3 по 5, проверив, что коды одинаковые (я просто следую учебнику и копирую-вставляю код, затем выполняю)

Ссылка на официальный учебник по Django с части 3 по 5.

Написание вашего первого приложения на Django, часть 3 Написание вашего первого приложения Django, часть 4 Написание вашего первого приложения Django, часть 5

Вернуться на верх