Not sure why am I getting this error because I only have 1 item in my ToDoList called "Habibs List" but when I go to http://127.0.0.1:8000/Habibs%20List , it's giving me this error:
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.
This is in my view:
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>")
My URLconf:
# 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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.