2017-04-05 12 views
0

私のstaticfilesは何に関係なく読み込まれません。私はstackoverflowを見て、5時間ドキュメントを読んでいます。スタティックファイルは登録されたタグではなく、staticfilesはロードされません。

はここ

urlpatterns = [ 
url(r'^admin/', admin.site.urls), 
url(r'', include('notebook.urls')) 
] 
from django.contrib.staticfiles.urls import staticfiles_urlpatterns 

urlpatterns += staticfiles_urlpatterns() 

一方、これは私のプロジェクトのために私の設定であると私は甚だしく私staticfilesがロードされていない理由を把握しようとしていurls.py

のための私のURLです。私はvirtualenvでこれを実行していないので、関連する問題に対処しました。私はDjangoのドキュメントを見て、私の設定でstaticfilesがロードされていない理由を見つけました。答えは役に立った。

これはここだけで完全なものにするためのプロジェクト

""" 
Django settings for onesky project. 

Generated by 'django-admin startproject' using Django 1.10.5. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.10/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/1.10/ref/settings/ 
""" 

import os 

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


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ 

# Static file directory 
TEMPLATE_DIR = os.path.join(BASE_DIR, "templates") 
# Static files for multiple directories 
STATICFILES_DIR = os.path.join(BASE_DIR, "static") 
# Media file directory 
MEDIA_DIR = os.path.join(BASE_DIR, "media") 

# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = 'q*6q$)mqhr**pwaj4m!8km&2i7s2ewu+lg%7p$*pm6+8!l8cwf' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.staticfiles', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'rest_framework', 
    'notebook', 

] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
] 

ROOT_URLCONF = 'onesky.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [TEMPLATE_DIR], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
       'django.template.context_processors.media', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'onesky.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 


# Password validation 
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators 

AUTH_PASSWORD_VALIDATORS = [ 
    { 
     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 
    }, 
] 


# Internationalization 
# https://docs.djangoproject.com/en/1.10/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.10/howto/static-files/ 
STATIC_URL = '/static/' 
STATIC_ROOT = STATICFILES_DIR 

# Media Root 
MEDIA_ROOT = MEDIA_DIR 
MEDIA_URL = '/media/' 

のための私の設定ファイルでもwgsi.pyファイルである

""" 
WSGI config for onesky project. 

It exposes the WSGI callable as a module-level variable named ``application``. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ 
""" 

import os 

from django.core.wsgi import get_wsgi_application 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "onesky.settings") 

application = get_wsgi_application() 

ここに私のテンプレートコードは

<!DOCTYPE html> 
<html lang="en"> 
<head> 
{% load staticfiles %} 

    <meta charset="UTF-8"> 
    <title>OneSky</title> 
    <link rel="stylesheet" href="{% load static "css/normalize.css" %}"> 
    <link rel="stylesheet" href="{% load static'css/home.css' %}"> 
    <link rel="stylesheet" href="{% load static '/css/notebook.css' %}"> 
    <link rel="stylesheet" href="{% load static 'css/skeleton.css' %}"> 
</head> 
<body> 
<div class="row" style="padding-top: 1%;"> 
    <div class="nav"> 
     <div class="three columns"> 
      <div class="logo">OneSky</div> 
     </div> 
     <!-- 
      @TODO:Change to class based styling 
     --> 
     <div class="seven columns" style="height: 100%"> 
      <div class="spacer"></div> 
     </div> 
     <div class="one column"> 
      <img src="{% load static 'img/settings-cog.png' %}" class="icon"> 
     </div> 
     <div class="one column"> 
      <img src="img/account.png" class="icon"> 
     </div> 
    </div> 
</div> 
<div class="data-container"> 
<div class="row"> 

     <div class="three columns" style="overflow: hidden"> 
      <div class="scroll-container"> 
      <div class="note-container"> 
      <div class="row"> 
       <div class="eight columns"> 
        <h2 class="note header"> Notebook </h2> 
       </div> 
       <div class="two columns"> 
        <img src="img/add-button.png" class="icon"> 

       </div> 
       <div class="two columns"> 
        <img src="img/list-button.png" class="icon"> 
       </div> 
      </div> 
       <div id="content" class="hiddenscrollbars"> 
       <hr> 
        {% for post in posts %} 

          <div class="row"> 
        <div class="note-title"> 
         <h4> {{ post.title }}</h4> 
        </div> 
       </div> 
        {% endfor %} 

      </div> 

       </div> 

     </div> 
      </div> 
    </div> 


<div class="eight columns"> 
    <div class="row"> 
     <h3 class="selected-note-title">Select Something</h3> <span><button class="submit" title="submit">Save</button></span> 
    </div> 
    <div class="scrolling-container"> 
     <div class="editor-container"> 
     </div> 

    </div> 
</div> 

</div> 
</div> 








</body> 
<!-- Include the Quill library --> 
<script src="js/quill.js"></script> 
<!-- Initialize Quill editor --> 
<script src="js/notebook.js"></script> 


</html> 

は中ありがとうございます援助のために進める

+0

、そしてどのようなあなたがそれにアクセスしようとするとエラーが発生しますか? –

+0

'' img ''は登録済みのタグライブラリではありません。 admin_list admin_modify admin_static admin_urlsあなたがあなたの質問を更新しても、関連するテンプレートコードを追加してくださいすることができ キャッシュ 国際化 ローカライゼーション ログ rest_framework 静的 staticfiles でtz @almostabeginner –

+0

、感謝:のいずれかでなければなりません。 –

答えて

0

staticを使用して静的ファイルのURLを取得する必要があります。代わりにload staticを使用しています.Djangoがカスタムタグを読み込んでいると思うのは混乱します。

あなたがloadを使用する必要がある唯一のインスタンスである:

{% load staticfiles %} 

変更これら:

<link rel="stylesheet" href="{% load static "css/normalize.css" %}"> 
<link rel="stylesheet" href="{% load static'css/home.css' %}"> 
<link rel="stylesheet" href="{% load static '/css/notebook.css' %}"> 
<link rel="stylesheet" href="{% load static 'css/skeleton.css' %}"> 
.... 
.... 
<img src="{% load static 'img/settings-cog.png' %}" class="icon"> 

へ:

あなたがそれにアクセスしようとしましたか
<link rel="stylesheet" href="{% static "css/normalize.css" %}"> 
<link rel="stylesheet" href="{% static'css/home.css' %}"> 
<link rel="stylesheet" href="{% static '/css/notebook.css' %}"> 
<link rel="stylesheet" href="{% static 'css/skeleton.css' %}"> 
.... 
.... 
<img src="{% static 'img/settings-cog.png' %}" class="icon"> 
+0

私はあなたに感謝しています....私は何を言うべきかも知らない。 –

+0

@travissmithがうれしい。 –

関連する問題