Getting Django's staticfiles includes working inside Vue.js .vue templates

Viewed 1243

I have a Django SPA built with Vue.js v2 / webpack.

I want to be able to use Django static template tags to add in references to images, etc inside Vue.js template .vue files.

Right now in my base.html template for Django:

{% load static %}
{% load render_bundle from webpack_loader %}
<html>
   <head>
      <!-- This works fine here! -->
      <link rel="stylesheet" href="{% static 'css/test.css' %}" />
      ...
   </head>
   <body> 
      <div id="app">
        <!-- Vue.js app gets mounted here -->
      </div>
   </body>
</html>

and that is of course the HTML page I use for the SPA (single page application).

But when I try to use static tags in my .vue template files like so:

{% static 'js/test.js' %}

It doesn't work - it never gets interpolated because of course Django is server-side and Vue is client-side.

I want to keep using the staticfiles tags (and not hard links) because I use different storage backends for static files, media, and even from local/staging/prod environments.

Any ideas for how to handle this with Django/Vue.js? What's a good solution here to get staticfiles linking into templates clientside?

1 Answers
Related