[Fixed]-Django collectstatic no such file or directory

7👍

Files in STATICFILES_DIRS need to have absolute path.
Use normpath.

STATICFILES_DIRS = (
    normpath(join(BASE_DIR, 'static')),
    normpath(join(BASE_DIR, 'upload')),
)

Also it is good to set STATIC_ROOT to something like

STATIC_ROOT = normpath(join(BASE_DIR, 'assets'))

and STATIC_URL

STATIC_URL = '/static/'

27👍

try this:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

and leave this empty, since you are using STATIC_ROOT

STATICFILES_DIRS = (
  # Put strings here, like "/home/html/static" or "C:/www/django/static".
  # Always use forward slashes, even on Windows.
  # Don't forget to use absolute paths, not relative paths.
)

it should work this way.

1👍

So I was having similar problem and followed what fraggles had suggested, but I was getting this follow up error:

NameError: name 'normpath' is not defined

My work around was switching the ‘.dirname’ keyword for ‘.normpath’ keyword instead:

STATICFILES_DIRS = (
    os.path.join(os.path.normpath(BASE_DIR), "static")
)

And it worked like magic. Hopefully this solution also helps someone.

0👍

Just do this !

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  • and then run python manage.py collectstatic
  • this will create a new file staticfiles and will move all your static files inside it.
  • after that load static in your django template by using {% load static %} inside your head tag

Leave a comment