私はしばらくの間この問題を抱えていました.CSSファイルをあちこちに移動して設定を変更しようとしており、メディアのURLをいじっています.他の質問を読んでください。
私の CSS ファイルは /home/justin/test/static/ ディレクトリにあります。テンプレートは /test/templates ディレクトリにあります。
私の設定は次のとおりです。
STATIC_ROOT = '/home/justin/test/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/justin/test/static/',
)
私のURLは次のとおりです。
urlpatterns = patterns('',
url(r'^$', 'views.home'),
# Static Files
url(r'^static/(?P<path>.*)$','django.views.static.serve', {'document_root':settings.MEDIA_ROOT}),
)
メイン テンプレートには 3 つすべてが含まれています。
<link rel="stylesheet" href="/static/style.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}style.css" />
<link rel="stylesheet" href="{{ STATIC_URL }}/style.css" />
彼らは出てきます:
<link href="/static/style.css" rel="stylesheet"></link>
<link href="style.css" rel="stylesheet"></link>
<link href="/style.css" rel="stylesheet"></link>
最初は正しいファイルに出てきますが、うまくいきません。どんな助けでも本当に感謝しています。ありがとうございました。
私のviews.py:
from django.shortcuts import render_to_response
def home(request):
return render_to_response('index.html',{})
端末からの私のエラーは次のとおりです。
[16/Aug/2013 21:00:21] "GET /static/style.css HTTP/1.1" 500 1729