空路径与以下任何一个都不匹配:

zee*_*er0 4 python django django-models python-3.x

我正在使用 python 3.8,启动服务器时出现错误:

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Using the URLconf defined in djangoProject.urls, Django tried these URL patterns, in this order:

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

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Run Code Online (Sandbox Code Playgroud)

我的民意调查/urls.py:

   from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='index'),
]
Run Code Online (Sandbox Code Playgroud)

我的 djangoProject/urls.py:

  from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
    url("polls/", include('polls.urls')),
    url("admin/", admin.site.urls),
]
Run Code Online (Sandbox Code Playgroud)

Wil*_*sem 8

根 url 包含两项:polls/admin/。因此,这意味着如果您访问根 URL ( 127.0.0.1:8000/),它将不会触发任何视图,因为没有视图“附加”到该 URL 模式。因此,您将必须访问页面来触发视图,或者更改 URL 模式以index在访问根 URL 时启用访问视图。

选项一:参观/polls/

您可以通过以下方式访问该页面:

127.0.0.1:8000/polls/
Run Code Online (Sandbox Code Playgroud)

选项 2:链接index到根 URL

index您可以使用以下命令更改访问根 URL 时要触发的 URL 模式:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    #   ↓↓ empty string
    url('', include('polls.urls')),
    url('admin/', admin.site.urls),
]
Run Code Online (Sandbox Code Playgroud)