[Answer]-Is it possible to use tempatetags inside javascript in a django template?

1👍

If your template tags are in an external javascript file (i.e. a file in your STATIC_ROOT) then no your template tags won’t work, as django doesn’t serve those javascript files, your webserver does. Django only serves the rendered results of the template specified in your view, not any related javascript or css files.

If you wanted this to work, you would need to create an url and view to render the javascript with a context and serve it to the client, but this is a very bad idea. You are better off including the relevant javascript in your html file and using your template tags there, or finding another way to pass the results of your template tag to the external javascript

Leave a comment