2👍
✅
Short answer is no. But you can circumvent this, there’s two approaches I can think of:
- add a script with the urls you need in your base html template, they need to be available globally so that you can access them with other scripts
- make a script to generate a .js file with all your urls and place it with all the other staticfiles (django translations for js use a similar approach)
Approach 1, would be something like:
<html>
...
<script>
var myApp = {
URLS: {
login: {% url 'login' %},
welcome: {% url 'welcome' %},
...
}
}
</script>
<script>console.log("The login url is " + myApp.URLS.login + "!")</script>
<script src="script/that/uses/urls.js"></script>
...
</html>
Source:stackexchange.com