Django教程“写实际上起什么作用的视图”

DrZ*_*Zoo 0 python regex django

我一直在研究Django教程。我说的是“写出实际上可以做某事的视图”。(第3部分)

我正在尝试使用它为您提供的index.html模板,但我不断收到404错误,内容为

Request Method: GET
Request URL: http://127.0.0.1:8000/polls/index.html

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/ ^$ [name='index']
^polls/ ^(?P<question_id>\d+)/$ [name='detail']
^polls/ ^(?P<question_id>\d+)/results/$ [name='results']
^polls/ ^(?P<question_id>\d+)/vote/$ [name='vote']
^admin/
The current URL, polls/index.html, didn't match any of these.
Run Code Online (Sandbox Code Playgroud)

我不知道其中一个正则表达式是否错误?我已经把它弄乱了一阵子了,我没有运气去工作。

我可以去/ polls就好了。但是/polls/index.html不起作用。

任何帮助,将不胜感激。

我正在使用的Django版本是1.7.4

C.B*_*.B. 5

Django视图函数或类使用您定义的模板,因此您不必在URL中指定它。该urls.py文件与您定义的正则表达式匹配,以将请求发送到视图。

如果你真的想使用URL,你必须定义^polls/index.html$在你urls.py和它直接到您的视图。