I'm working on a basic URL builder project. In JavaScript, I have the following code snippet:
var url = document.URL;
To add something to the URL in Django, we can use the syntax below:
url = url + "{% url 'object_view' %}";
alert(url);
The issue arises when combining document.URL and Django's URL, resulting in a pattern like this:
http://localhost:8000//objects/view/
I've explored Javascript string manipulation methods such as trim()
and replace()
, but neither seems to offer a way to simply remove the extra slash from the document.URL
string.
If I replace all slashes, it may cause problems if, for instance, my document.URL
is structured as follows:
http://localhost:8000/something/something2/
Any ideas or suggestions?