Django教程:完成第一页后出现无法解释的404错误 [英] Django Tutorial: unexplained 404 error after completing first page
问题描述
我完成了 https://docs.djangoproject.com/en/1.9/intro / tutorial01 /
预期的行为有效。我的民意测验索引正在显示。但是有一个我不明白的意外结果。当我转到 localhost:8000
时,找不到页面。为什么?
The intended behaviour works. My polls index is showing. But there is one unintended consequence that I don't understand. When I go to localhost:8000
I get a page not found. Why?
这是我的 mysite / mysite / urls.py
,如本教程所述。
This is my mysite/mysite/urls.py
as the tutorial explained.
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
服务器说:
Not Found: /
[11/Feb/2016 04:25:46] "GET / HTTP/1.1" 404 2010
当我删除投票行时,404消失了。即:
When I delete the polls line, the 404 disappears. I.e.:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
]
现在服务器说:
Not Found: /
[11/Feb/2016 04:24:23] "GET / HTTP/1.1" 200 1767
所以我猜想这是一些默认的怪癖,但我仍然不完全知道自己是在犯错误还是行为已定义。我的其他代码与本教程的代码段相同。
So I guess it is some default quirk but I still don't fully know if I am making a mistake or if this is defined behaviour. My other code is the same as in the code snippets of the tutorial.
推荐答案
本教程没有定义当您转到您的网站根目录,它仅处理民意调查
应用。如果要在浏览到 http:// localhost:8080 /
时看到一些内容,则必须添加url映射。
The tutorial does not define what will happen when you go to your site root, it only deals with the polls
app. You have to add a url mapping if you want to see something when you browse to http://localhost:8080/
.
作为一个简单示例,请尝试在您的 mysite / urls.py
中进行以下更改:
As a simple example, try making the following changes in your mysite/urls.py
:
from polls import views
urlpatterns = [
url(r'^$', views.index, name='site_index'),
...
]
从现在,当您浏览到站点根目录时,应该会看到民意调查
应用程序的索引视图。
From now on you should see the index view of polls
app when you browse to your site root.
这篇关于Django教程:完成第一页后出现无法解释的404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!