Home > Blockchain >  django 404 error The current path, didn’t match any of these
django 404 error The current path, didn’t match any of these

Time:10-14

I have such error, when I try edit or delete:

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

create/
edit/<int:id>/
delete/<int:id>/
The current path, edit/, didn’t match any of these.

but I can't get what's wrong with path:

urls.py:

from django.urls import path
from lab4 import views
 
urlpatterns = [
    path("", views.index),
    path("create/", views.create),
    path("edit/<int:id>/", views.edit),
    path("delete/<int:id>/", views.delete),
]

Create works fine by the way, but what's the problem with edit and delete?

CodePudding user response:

As @Nealium stated in above comment, you should also give some id as you mentioned <int:id> in URL params for both the views.

So the requested URL should be http://127.0.0.1:8000/edit/1 (for edit view) and http://127.0.0.1:8000/delete/1 (for delete view).

CodePudding user response:

http://127.0.0.1:8000/edit/1/

In your case 1 is <int:id>. You forgot to pass a parameter to the url. Examples and description here

in the view it looks something like this:

def edit(request, id):
    print(id)

    return HttpResponse(f"""
        <p>Host: {12345}</p>""")
  • Related