I am new to Javascript and I am using Django.
I've read documentation about the Javascript fetch API but I'm confused about something - if anyone can explain it I'd really appreciate it.
I've seen code that didn't include a url for the API. Where is this coming from within the framework - when I write code, how do I know what to put right after the fetch part?
Example:
const load_like = (post, postLikes, likePost, current_user) => {
const csrftoken = getCookie('csrftoken');
fetch(`/post/${post.id}`, {
method: 'PUT',
body: JSON.stringify({
likes: [post.original_poster.id]
}),
headers: { "X-CSRFToken": csrftoken }
})
.then(response => response.json())
.then(data => {
display_likes(data, postLikes, likePost, current_user)
})
}
Is this done in urls.py ? For example would it be:
path("post/<int:post_id>", views.post, name="post" ),
I want to make sure I understand how to write this type of line and understand why these parts should go here:
fetch(`/post/${post.id}