You typically do not render
JavaScript files. The files are sent verbatim by the web server, so you cannot use template tags or filters in your .js files.
You do have a couple options.
First, and the method that we prefer, is to use the json_script
tag in the html for data needing to be rendered, and then access that data from the main part of your JavaScript code.
Or, you could use the include
tag to include your JavaScript file into the main part of your template. (It would need to be done inside a <script>
tag.)
(There are other options as well, but they get more and more “extreme” as you go along.)