Django: Set path for global static files

25 July 2018 — Written by Mitesh Patel

In Django all your custom js/css/images are placed in /static/ directory of your module, But global file should be placed in your application, Django is not supplied with already created / configured global static path. you have to configure it manually.

To configure it, we use "os" package to mange directory creations, Which is already imported in your as

import os

  • Go to of your project application
  • set STATIC_ROOT = os.path.join(BASE_DIR, "static")
  • And run django command python collectstatic
  • These will place your all modules/plugins static files into root static folder inside application folder.

STATIC_URL is independent of the name, it will create a kind of alias for your static path. so, optionally you can set it any thing else. like

STATIC_URL = '/assets/'

Copyright © 2022 Mitesh Patel. Built with Gatsby