Django 测试客户端:投票应用程序第 5 部分 NoReverseMatch

The Django test client: polls app part 5 NoReverseMatch

我正在关注 polls app 并且我正在复制所有内容以确保我拥有与他们拥有的 100% 相同的代码但是当我使用

response = client.get(reverse('polls:index'));

我遇到了一个巨大的错误,none 的注释对我来说很有意义。有人告诉我它与我的 views.py 有关,但我查看了 Django 网站,它与我的网站 100% 相同。这是我得到的错误:

django.urls.exceptions.NoReverseMatch: Reverse for 'vote' with arguments '('',)' not found. 1 pattern(s) tried: ['pools/(?P<question_id>[0-9]+)/vote/$']

看来您必须在 URL 上指定名为 question_id 的 GET 参数。

The NoReverseMatch exception is raised by django.urls when a matching URL in your URLconf cannot be identified based on the parameters supplied.

错误提示您必须提供问题 ID。我以1为例。

http://localhost:8000/pools/1/vote/