Search code examples
djangodjango-staticfiles

Django how to change static dir


Default dir for static folder is project/app/static but since I'm using some js and css libs and I have multiple apps I don't want my project gain some extra size. I wonder if I could move the static folder outside of the app folder. Like:

| project
| | app
| | static

Is this possible?


Solution

  • If you want to set static root at BASE root then you can go with this config

    settings.py

    STATIC_URL = 'static/'
    STATICFILES_DIRS = [BASE_DIR / 'static'] 
    

    Project directory

    enter image description here

    NOTE - using STATICFILES_DIRS = [BASE_DIR / 'static'] you can set custom static root,

    only you need to set static folder relative path in STATICFILES_DIRS = [BASE_DIR / 'relative path of sttic folder']