Reputation: 10398
I am trying to refer to a static file in an other static file but I can't figure out how to do it.
I have a javascript file that I include into the html page this way: {% static 'myJavascript.js' %}
Then, in myJavascript.js
I need to refer an other static file (a .json
file ) but it wont works when I use {% static 'myJson.json' %}
.
Any one have an idea? Thanks in advance
Upvotes: 0
Views: 72
Reputation: 5629
Static files are static, which means they are not interpreted by Django, so cannot use tags in them.
However, you can refer to a static file from any other static file using relative paths assuming that the file is accessible.
There are a lot of topics on SO referring to how to include one javascript file from another one, for example: How do I include a JavaScript file in another JavaScript file?
Upvotes: 1
Reputation: 6488
Use a normal absolute/relative path to refer to files inside *.js
files.
Static files are only served, not rendered by Django, therefore you can't use template tags inside of them.
Upvotes: 0