【发布时间】:2017-05-27 01:58:00
【问题描述】:
我知道以前有人问过这个问题,但我还没有找到解决我问题的答案。
我正在查看 Django tutorial,我已经按照教程中的内容逐字逐句设置了第一个 URL,但是当我转到 http://http://localhost:8000/polls/ 时,它给了我这个错误:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/ ^% [name='index']
^admin/
The current URL, polls/, didn't match any of these.
我正在使用 Django 1.10.5 和 Python 2.7。
这是我在相关网址和查看文件中的代码:
在 mysite/polls/views.py 中:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
在 mysite/polls/urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^%', views.index, name='index'),
]
在 mysite/mysite/urls.py:
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),
]
发生了什么事?为什么我会收到 404?
【问题讨论】: