2016-09-08 4 views
0

Ich entwickle Web mit Django-Framework.Django - Statische Datei kann nicht geladen werden (Fehler 404)

So habe ich 3 Ordner in meiner statischen Datei wie folgt.

*web 
    *home 
    *static 
    *admin 
    *scripts 
    *styles 
    *web 
    *manage.py 
    *db.sqlite3 

und ich habe meine Einstellungsdatei mit diesem statischen Setup

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR, 'static') 
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) 

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'), 
) 

Aber wenn ich manage.py collectstaitc ich dieses Ergebnis zu erhalten geben Sie python3

Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/Users/pwanhsu/django/django/core/management/__init__.py", line 349, in execute_from_command_line 
    utility.execute() 
    File "/Users/pwanhsu/django/django/core/management/__init__.py", line 341, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/Users/pwanhsu/django/django/core/management/base.py", line 290, in run_from_argv 
    self.execute(*args, **cmd_options) 
    File "/Users/pwanhsu/django/django/core/management/base.py", line 341, in execute 
    output = self.handle(*args, **options) 
    File "/Users/pwanhsu/django/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle 
    collected = self.collect() 
    File "/Users/pwanhsu/django/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect 
    for path, storage in finder.list(self.ignore_patterns): 
    File "/Users/pwanhsu/django/django/contrib/staticfiles/finders.py", line 112, in list 
    for path in utils.get_files(storage, ignore_patterns): 
    File "/Users/pwanhsu/django/django/contrib/staticfiles/utils.py", line 28, in get_files 
    directories, files = storage.listdir(location) 
    File "/Users/pwanhsu/django/django/core/files/storage.py", line 286, in listdir 
    for entry in os.listdir(path): 
FileNotFoundError: [Errno 2] No such file or directory: '/Users/pwanhsu/Desktop/v_bridge/web/web/static' 

I successfuly statische Datei sammeln kann Wenn ich das STATICFILES_DIRS wie folgt entferne

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR, 'static') 

0 static files copied to '/Users/pwanhsu/Desktop/v_bridge/web/static', 56 unmodified. 

In meiner HTML-Datei, ich habe diese Codes

{% Last Static%}

Aber der Server zurückgeben mir einen 404-Fehler

[08/Sep/2016 03:36:45] "GET/HTTP/1.1" 200 5831 
[08/Sep/2016 03:36:45] "GET /static/scripts/bootstrap/css/bootstrap-responsive.min.css HTTP/1.1" 404 1763 
[08/Sep/2016 03:36:45] "GET /static/scripts/icons/social/stylesheets/social_foundicons.css HTTP/1.1" 404 1775 
[08/Sep/2016 03:36:45] "GET /static/scripts/icons/general/stylesheets/general_foundicons.css HTTP/1.1" 404 1781 

Wer Ahnung hat, darüber, wie Sie richte den statischen Pfad ein oder was ich falsch gemacht habe. Verwechsle es wirklich.

Antwort

0

Verwenden STATICFILES_DIRS = ('/ statisch') oder

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),) 
1

Ihr settings.py in web/web/ Verzeichnis ist. Sie static Verzeichnis ist in web/ Verzeichnis. In diesem Fall Satz:

STATIC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'static)) 

STATICFILES_DIRS definiert den weiteren Standorten die Static. Sie benötigen diese Einstellungen nicht.

+0

Server gibt mir das zurück "Die STATICFILES_DIRS-Einstellung sollte die STATIC_ROOT-Einstellung nicht enthalten" – Pwan

0

Try BASE_DIR in staticfiles_dir zu verwenden:

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] 

oder

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'web/static')] 
0
STATIC_ROOT='static' 
SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) 
STATIC_URL = '/static/' 
STATICFILES_DIRS = [ 
    os.path.join(SITE_ROOT ,'/static/'), 
] 

Dies ist Schnipsel tatsächlich von einem meines projects.In des Anfangs, ich habe auch mit statischen Dateien zu kämpfen Dies sollte Ihr Problem beheben. Wenn Sie immer noch 404 erhalten. Überprüfen Sie die Berechtigungen für statische Dateien und statische Dateien

Verwandte Themen