Skip to content

404 when trying to get local font files #162

@antonpetrov145

Description

@antonpetrov145

Issue is this - when I try to serve a local font file from a css file I get 404 errors all around
in css

@font-face {
  font-family: "Lato";
  font-style: normal;
  font-weight: 900;
  font-display: swap;
  src: url("@/css/fonts/lato-v20-latin-ext_latin-900.woff2")
    format("woff2");
  src: local(""),
    url("@/css/fonts/lato-v20-latin-ext_latin-900.woff") format("woff"),
    /* Modern Browsers */
      url("@/css/fonts/lato-v20-latin-ext_latin-900.ttf")
      format("truetype"); /* Safari, Android, iOS */
}

vite.config

export default defineConfig({
  base: "static/", // match STATIC_URL from django
  resolve: {
    alias: {
      "@": resolve("./static")
    }
  },
  build: {
    manifest: "manifest.json",
    outDir: resolve("./assets"),
    rollupOptions: {
      input: {
        test: resolve("./static/js/main.js"),
      },
    },
  },
  plugins: [tailwindss()]
});

settings.py

STATIC_URL = "static/"
MEDIA_URL = "/images/"

DJANGO_VITE = {"default": {"dev_mode": DEBUG}}

STATICFILES_DIRS = [
    BASE_DIR / "assets",
    BASE_DIR / "static",
]

STATIC_ROOT = BASE_DIR / "staticfiles"
MEDIA_ROOT = BASE_DIR / "static/images"

main.js

import "@/css/styles.css";

When I try to load the font I see that the url is /static/static/css/fonts while it needs to be /static/css/fonts
What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions