Victor Polevoy Victor Polevoy -4 years ago 325
Python Question

Django collectstatic no such file or directory

In django 1.7 collectstatic throws an exception for me:

OSError: [Errno 2] No such file or directory: '/static'

I've performed a lot of
-calls and everything worked fine, but today have this issue.

BASE_DIR = os.path.dirname(os.path.realpath(__file__))


STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_URL.strip("/"))


BASE_DIR is correct, checked it. Directory BASE_DIR/static/ exists and all my static files are there.


Traceback (most recent call last):
File "../", line 10, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/core/management/", line 399, in execute_from_command_line
File "/usr/local/lib/python2.7/dist-packages/django/core/management/", line 392, in execute
File "/usr/local/lib/python2.7/dist-packages/django/core/management/", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/", line 415, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/", line 173, in handle_noargs
collected = self.collect()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/", line 103, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/", line 106, in list
for path in utils.get_files(storage, ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/", line 25, in get_files
directories, files = storage.listdir(location)
File "/usr/local/lib/python2.7/dist-packages/django/core/files/", line 249, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/static'

Any suggestions?

Answer Source

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

    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'))


STATIC_URL = '/static/'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download