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:

在这里插入图片描述
跟着教程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)是该文件自带的,于是 试一下

在这里插入图片描述
既然这样
在这里插入图片描述
成功

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

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值