我之前已经问过这个问题,但我找不到解决问题的答案。
我正在查看Django tutorial,我已经按照教程的说法完全设置了第一个网址,但是当我转到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?
答案 0 :(得分:4)
您的网址配置正确不正确,您必须使用UIView.animate(duration: 0.3) {
self.collectionView.layoutIfNeeded()
}
代替$
。
%
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
充当正则表达式标志,用于定义正则表达式的结尾。
答案 1 :(得分:1)
urlpatterns = [path('', views.index, name='index'), ]