Skip to content
Advertisement

JSON POST and GET 404 (Not Found)

I am trying to create an API in Django but am receiving the following errors message in the JavaScript console.

JavaScript

Does anyone know how to fix this problem?

API url: path("edit/<int:post_id>", views.edit, name="edit")

views.py

JavaScript

JavaScript

JavaScript

HTML

JavaScript

I think something might be wrong in the way I am passing in the id to the API, but I am not sure. Could the for loop in the HTML be causing the problem?

models.py

JavaScript

Advertisement

Answer

you call edit_email without id here:

JavaScript

of cause, after call you get /edit/undefined on this line:

JavaScript

you don’t send anything like id, I can imagine it should be something like this:

JavaScript

You will also need to pass the value property to the button as post.id assuming that the post object will have an id key in your for loop.

If you are getting a reference error you need to check if page_obj.object_list has an id key for all the posts.

Advertisement