2011-12-26 10 views
1

私はWinVistaでDjango 1.3.1とPython 2.7を使用しています。私は、ローカルの開発者であろうと、私のホストに配備されたにせよ、同じ問題を経験しています。私のサイトの静的メディアを示してのメインページでサイトの先頭ページにDjangoの静的ファイルをロード

:二次ページのCSSで

http://www.drugpolicyreformmovement.com

、画像などを表示しません。

http://www.drugpolicyreformmovement.com/newsarchive2003

http://www.drugpolicyreformmovement.com/newsarchive2010

または

http://www.drugpolicyreformmovement.com/newsarchive2009

「のrunserverを管理」の出力は、それらの二「newsarchive」ページ上の静的メディアの404エラーを示しています。どうやら 'document_root'は、メインページではなく、セカンダリページでは異なるので、 '/ static'をすべて '/ static'で探しているのではなく、それらのセカンダリページで '/ newsclippings2003/static'フロントページ用。私はあなたに関連しているので、私はここに、全ファイルが含まれている私のURLconfのかわからない

再び
import os 
from django.conf.urls.defaults import * 
from django.views.generic import ListView, YearArchiveView 
from newsclippings.models import Article 
from drugpolicyreformmovement.views import ArticleYearArchiveView 

# Uncomment the next two lines to enable the admin: 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    (r'^$', ListView.as_view(
     queryset = Article.objects.order_by("-date", "publication", "author", "headline"), 
     context_object_name='articles', 
     template_name='index.html')), 
    (r'^newsarchive(?P<year>\d+)/$', ArticleYearArchiveView.as_view()), 
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', 
     { 'document_root' : os.path.join(os.path.dirname(__file__), 'static') }), 
    # url(r'^drugpolicyreformmovement/', include('drugpolicyreformmovement.foo.urls')), 

    # Uncomment the admin/doc line below to enable admin documentation: 
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 

    # Uncomment the next line to enable the admin: 
    (r'^admin/', include(admin.site.urls)), 
) 

を、私はこれが問題の行だと思う:

(r'^static/(?P<path>.*)$', 'django.views.static.serve', 
    { 'document_root' : os.path.join(os.path.dirname(__file__), 'static') }), 

URLconfエントリをどのような順序で配置しても問題ありません。この行は、デプロイ時に変更する必要がないように設計されています。

答えて

2

最初のページで、あなたのURLが

http://www.drugpolicyreformmovement.com/static/css/blueprint/print.css 

http://www.drugpolicyreformmovement.com/newsarchive2003/static/css/blueprint/print.css 

ちょうどURLで/追加または例えば{{ STATIC_URL }}

使用

  • /static/css/blueprint/print.css

または

  • <img src="{{ STATIC_URL }}css/blueprint/print.css" />

設定

でちょうど設定STATIC_ROOTこちらを参照してください。

1

私はhtmlのソースを見ると、静的資産のパスが表示されます。 絶対パスを使用する必要があります!

これは間違っている:

<link rel="stylesheet" href="static/css/blueprint/screen.css" media="screen, projection"> 

これを使用して:

<link rel="stylesheet" href="/static/css/blueprint/screen.css" media="screen, projection"> 

ほとんどの場合、それは間違っている、あなたのテンプレートがありますが、あなたはあなたのテンプレートファイルを示しませんでした。

1

URLに対応するのではなく、テンプレートに{{STATIC_URL}}テンプレートタグを使用する必要があります。デプロイ時に変更を加える必要はなく、別のコンテキスト変数を扱う心配はありません。内側のページで

関連する問題