0

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

Leistungsabfall
  • 6,368
  • 7
  • 33
  • 41
farhawa
  • 10,120
  • 16
  • 49
  • 91

2 Answers2

1

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?

Community
  • 1
  • 1
pkacprzak
  • 5,537
  • 1
  • 17
  • 37
0

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.

Leistungsabfall
  • 6,368
  • 7
  • 33
  • 41