首页 > 解决方案 > 使用 SQLite3 找不到 Django 页面

问题描述

不知道为什么我会收到此错误,因为我的 ToDoList 中只有一项名为“Habibs List”,但是当我转到http://127.0.0.1:8000/Habibs%20List时,它给了我这个错误:

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

admin/
<int:id> [name='index']
The current path, Habibs List, didn't match any of these.

这在我看来:

def index(response, name):
    ls = ToDoList.objects.get(name=name)
    item = ls.item_set.get(id=1)
    return HttpResponse("<h1>%s</h1><br></br><p>%s</p>" % (ls.name, str(item.text)))

# def v1(response):
#     return HttpResponse("<h1>Game Page</h1>")

# def v2(response):
#     return HttpResponse("<h1>Electronic Page</h1>")

我的网址配置:

# the path to our different web pages
# like the different views we have in our file
from django.urls import path
from . import views

urlpatterns = [
    path("<int:id>", views.index, name="index"),
]

标签: pythondjango

解决方案


在您的代码中,您只能将您的 url 路径更改为path("<str:name>/", views.index, name="index")


推荐阅读