【发布时间】:2014-02-01 16:37:33
【问题描述】:
我似乎无法让https://docs.djangoproject.com/en/1.6/intro/tutorial03/ 的教程工作。尝试访问http://127.0.0.1:8000/index.html 或http://127.0.0.1:8000/ 时出现以下错误
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/index.html
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/
^admin/
The current URL, index.html, didn't match any of these.
我将 /mysite/urls.py 设置为:
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
而index.html在/polls/templates/polls/index.html
【问题讨论】:
-
请参阅docs.djangoproject.com/en/dev/topics/http/urls 了解有关 Django 如何解析 url 的更多信息。在 Django 中,一个 url 指向一个 view function 而不是一个文件。 urlconf(在您的
urls.py中)定义了 url 和视图函数之间的映射