In the realm of Django, I find myself faced with the challenge of loading a JavaScript file that matches the name of the view whenever I call said view with a template.
For example, if I invoke the view foo
, my goal is to automatically load foo.js
from a specific (public) directory, provided it exists.
Creating this functionality within a template is straightforward - simply passing a list of JavaScript files to be loaded and handling this in a base template. But how can I achieve this generically for each view without having to manually code it into every single one? Could a context processor help me accomplish this task effortlessly?