2016-09-08 12 views
0

私はdjangoフレームワークでWebを開発しています。Django - 静的ファイルを読み込めません(404エラー)

私はこのような静的ファイルに3つのフォルダを持っています。

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

と私はsuccessfuly静的なファイルを収集することができます私はこの静的な設定で自分の設定ファイル

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

を持っている。しかし、私はmanage.py collectstaitcをの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' 

を取得このようなSTATICFILES_DIRSを削除すると、

# 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. 
012私のHTMLファイルに

、私が持っているこれらのコード

{%負荷staticfiles%}

しかし、サーバーは私に

[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 

誰もがどのようにについての考えを持っている404エラーを返します静的なパスを設定するか、私が間違っていたものを設定してください。本当にそれと混同します。

答えて

0

使用 STATICFILES_DIRS =( '/静的') または

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

あなたsettings.pyweb/web/ディレクトリにあります。あなたstaticディレクトリはweb/ディレクトリにあります。この場合、設定:

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

STATICFILES_DIRSは追加の場所staticfilesを定義します。この設定は必要ありません。

+0

サーバーは私にこれを返します "STATICFILES_DIRS設定はSTATIC_ROOT設定を含むべきではありません" – Pwan

0

はstaticfiles_dirでBASE_DIRを使用してみてください:

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

または

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/'), 
] 

これは実際に私のprojects.In初めの1からの抜粋された、私はあまりにも静的ファイルで苦労しています。これで問題は解決するはずです。まだ404を取得している場合は、静的ファイルdirと静的ファイルのアクセス許可を確認してください。

関連する問題