python - 使用 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"),
]
解决方案
在您的代码中,您只能将您的 url 路径更改为path("<str:name>/", views.index, name="index")
推荐阅读
- javascript - 通过 map 对多个元素反应 refs
- postgresql - Heroku 无法与 Postgres DB/Knex/Express 连接
- java - 我的代码会编译,但是当我运行它时,它有一个错误。为什么?
- javascript - 递增 1,然后 10,然后 100?
- typescript - 如何将函数添加到命名空间
- c# - 如何引用 2 个具有相同名称的不同 DLL?
- java - 为什么使用 PrintWriter 发送字符串后 JAVA BufferedReader 无法从 python 客户端接收字符串?
- javascript - Swagger UI 3.19.4(Swagger 2.0)查询参数选择
- node.js - 如何让节点应用程序看到 Google Cloud 上的系统变量?
- ios - AppStore Connect 显示的屏幕截图颜色空间错误