Django 404错误GET请求URL:当请求空白URL时,http:// localhost:8000 /不断弹出

问题描述

我正在看汤姆·阿廷的本教程。

我的代码与书中的代码完全相同,但是,每次我尝试在localhost服务器上呈现我的网页时,我总是收到找不到页面(404)的错误

这是我的项目(配置)网址:

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

import core.urls

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

这是我的应用(核心)网址:

from django.urls import path
from . import views


app_name ='core'
urlpatterns = [
    path('movies',views.MovieList.as_view(),name = 'MovieList'),]

这是我的应用(核心)视图:

from django.views.generic import ListView

from core.models import Movie


# Create your views here.
class MovieList(ListView):
    model = Movie

这是我的应用(核心)管理员

from django.contrib import admin

# Register your models here.

from core.models import Movie

admin.site.register(Movie)

我不知道为什么请求与''网址不匹配。

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

admin/
movies [name='MovieList']
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.

解决方法

您需要以下内容:

http://localhost:8000/

但是,您尚未为此创建任何路由。根据您的urlconf,您可以尝试以下操作:

localhost:8000/admin/
localhost:8000/core/movies