在Django中找不到页面(404)

2024-03-29 04:57:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Django 2.0有点问题。在我的例子中,调试器用以下消息响应:

Page not found (404)
Request Method: GET
Request URL:    http://localhost:8000/

使用bajkowo.urls中定义的URLconf,Django按以下顺序尝试了以下URL模式:

^{pr2}$

但这导致了一个错误:

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.

我已经检查了视图和网址,但我没有发现一个错误或打字错误。有人能查一下我的密码吗?在

网址.py:

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

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

巴基/网址.py:

from django.urls import path
from . import views

urlpatterns = [
    path('bajki/',views.lista_bajek, name='lista_bajek'),
]

巴基/视图.py:

from django.shortcuts import render

def lista_bajek(request):
    return render(request, 'bajki/lista_bajek.html', {})

def lista_bajek应以空白网站响应,但返回404错误代码。当然,我确实创建了bajki/templates/bajki/lista_bajek.html文件。在


Tags: pathdjangofrompyimporturladminrequest