[Fixed]-Pixi.js can't load images because Django "can't find them"

1👍

Django should only serve assets from your static location. So in this case, you should be able to find the files by adding game/ to the path.

PIXI.loader
  .add([
    "{% static 'game/images/quarter.png' %}",
    "{% static 'game/images/c_quarter.png' %}",
    "{% static 'game/images/clef.png' %}",
    "{% static 'game/images/heart.png' %}"
  ])

To make sure that your static assets are included when you do collectstatic, read the documentation to understand how this works. It’s better to understand what is happening than to paste the files everywhere until it works.

Files are searched by using the enabled finders. The default is to
look in all locations defined in STATICFILES_DIRS and in the ‘static’
directory of apps specified by the INSTALLED_APPS setting.

So the common practice is to have a static folder inside each app that contains static assets. Those are then copied by django to the location where your static files will be served from.

Leave a comment