I currently have a pretty long, one-time-use variable that is passed into a data visualization library in my template. For general cleanliness, it would be better if I were able to store that variable in a .js file (in my static folder) and export it, then access it within my template’s . Is it possible to import or assign variables from my static .js files to my template?
thanks!
In general, I’d say you’re going in the wrong direction.
Remember, the Django code, including template rendering, occurs on the server. JavaScript runs in the browser. By the time the browser is running the JavaScript, your Django view / template rendering is done.
I would go in the other direction. I would store that variable within Django, and then pass it to the JavaScript when rendering the template, allowing Django to manage that value.
(You could read the .js file, and parse it yourself to find this variable, but it’s not an approach I would take.)
Ken