Django报错 Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

Django入门

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

Django报错 Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:_第1张图片
跟着教程https://docs.djangoproject.com/zh-hans/2.0/intro/tutorial01 , 走到创建应用polls后,再运行

python manage.py runserver

打开localhost:8000 报错!小白,也不知道哪里错了,,,反复试,,还是不懂,最后认真得跟着教程走。

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

polls/
admin/
The empty path didn’t match any of these.

URLconf 是啥,

#polls/urls.py 
from django.urls import path
from . import views
urlpatterns = [
    path('', views.index, name='index'),
]

views是我们需要打开的视图,polls/urls.py是我们创建的URLconf,为了使得能在mysite项目下运行polls这个应用,我们还需在mysite/urls.py中引入polls.urls以便请求能够正确找到路径。

于是,在mysite/urls.py中配置URLconf,

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

path(‘admin/’, admin.site.urls)是该文件自带的,于是 试一下

Django报错 Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:_第2张图片
既然这样
Django报错 Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:_第3张图片
成功

好吧,原来加个在localhost:8000后加个/polls 请求到正确地址就行。。。。。

你可能感兴趣的:(Django报错 Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:)