【问题标题】:Django: index.html url cannot be found (Django polls tutorial)Django:找不到 index.html url(Django 投票教程)
【发布时间】:2014-02-01 16:37:33
【问题描述】:

我似乎无法让https://docs.djangoproject.com/en/1.6/intro/tutorial03/ 的教程工作。尝试访问http://127.0.0.1:8000/index.htmlhttp://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 和视图函数之间的映射

标签: python django


【解决方案1】:

您的 urls.py 中的 URL 是您可以访问的;所以要么

http://127.0.0.1:8000/admin/
http://127.0.0.1:8000/polls/

如果这两个子应用程序(管理员和民意调查)都为空字符串 ("^$") 定义了一个视图,我相信它们都会这样做。

其中一个视图碰巧使用了名为“index.html”的模板这一事实并不意味着该文件名也用于 URL。

【讨论】:

    猜你喜欢
    • 2022-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 2014-09-18
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多