2014-09-23 8 views
7

In django 1.7 collectstatic eine Ausnahme für mich wirft:Django collectstatic keine solche Datei oder das Verzeichnis

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

ich viel collectstatic -calls durchgeführt haben und alles hat gut funktioniert, aber heute haben dieses Problem.

settings.py

BASE_DIR = os.path.dirname(os.path.realpath(__file__)) 
INSTALLED_APPS = (
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 

    'fxblog', 
    'rest_framework', 
) 

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

STATICFILES_DIRS = (
    '/static/', 
    '/upload/', 
) 

BASE_DIR korrekt ist, überprüft es. Verzeichnis BASE_DIR/static/exists und alle meine statischen Dateien sind da.

Traceback:

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

Irgendwelche Vorschläge?

+0

'STATIC_ROOT = os.path.join (BASIS_DIR, 'sitestatic')' –

+0

Gleiche Ausgabe - 'OSError: [Errno 2] Keine solche Datei oder kein Verzeichnis: '/ static''aber Verzeichnis (in der Ausgabe) geändert in sitastatisch. –

+0

was ist das? '' STATIC_ROOT = os.path.join (BASE_DIR, '/ static') ''. das sollte funktionieren. '' strip'' strippt beide '' '' '' '' '' '' – doniyor

Antwort

4

Dateien in STATICFILES_DIRS müssen absoluten Pfad haben. Normpfad verwenden.

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

Auch ist es gut STATIC_ROOT um so etwas wie

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

und STATIC_URL

STATIC_URL = '/static/' 
+1

Versucht Ihre Lösung auch - es hat funktioniert, danke auch. –

11

zu setzen versuchen Sie dies:

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

und lassen Sie dieses Feld leer, da Sie verwenden 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. 
) 

sollte es so funktionieren.

+0

Versuchte deine Lösung - es hat funktioniert, danke. –

+1

Leider habe ich zuerst die Lösung von @fragles ausprobiert, daher kann ich Ihre Antwort nur verbessern. –

+1

Danke, das hat für mich funktioniert :) – valkirilov

0

So war ich ähnliches Problem mit und gefolgt, was fraggles vorgeschlagen hatte, aber ich war immer diese Follow-up-Fehler:

NameError: name 'normpath' is not defined 

Meine Arbeit rund um die '.dirname' Schlüsselwort wurde Schalt für‘.normpath 'Stichwort stattdessen:

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

Und es funktionierte wie Magie. Hoffentlich hilft diese Lösung auch jemandem.

Verwandte Themen