【问题标题】:Django 404 error GET Request URL: http://localhost:8000/ keeps popping up when blank url is requestedDjango 404 error GET Request URL: http://localhost:8000/ 在请求空白 url 时不断弹出
【发布时间】:2021-02-08 03:31:42
【问题描述】:

我正在学习 tom artyn 的这个教程。

我的代码与书中他的完全一样,但是,每次我尝试在 localhost 服务器上呈现我的网页时,我都会不断收到 Page not found (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)

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

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.

【问题讨论】:

    标签: python django


    【解决方案1】:

    您要求以下内容:

    http://localhost:8000/
    

    但是,您还没有为此创建任何路线。根据您的 urlconf,您可以尝试以下内容:

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

    【讨论】:

    • 谢谢先生!对像我这样的新手有很大的帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多