I am working on a Django project and got stuck on url patterns and routes.
On index.html, the pathname is "" and the JS functions are working great. The fetch url tweets/${tweetid} is matching with Django API route url pattern tweets/<int:tweetid> and is working fine.
However, on profile.html, the pathname is "profile/<int:userid>" and JS is not working here. The fetch url tweets/${tweetid} results the final path profile/tweets/<int:tweetid>. Since that is not in urls.py, I am getting an error.
How can I execute my fetch and JS functions on any html page in this web application?
You should start the path with a leading slash (/) to use an absolute path, not a relative path, so:
/tweets/${tweetid}
The leading slash means that it will for example fetch the page hostname.ext/tweets/1234. If you use a relative path (without a leading slash), the item will be appended to the already specified path.