Reputation: 3025
I would like to be able to DRY out my static files by using a template tag, like {% url 'my_view' %}
, in my static file, instead of /path/to/my_view
. Is there a way to do this?
Upvotes: 1
Views: 981
Reputation: 2136
Short answer is no. But you can circumvent this, there's two approaches I can think of:
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>
Upvotes: 2