開発中に静的ファイルをセットアップしようとしています。私はpolls/static/images/banner.jpgにある画像を持っています。 127.0.0.1:8000に移動すると、バナーが表示されますが、127.0.0.1:8000/2ndpageのようなものに移動すると、バナーが破損します。Django:スタティックファイルイメージメインページテンプレート以外のURLパスが壊れます
私のインデックスが(URLは:127.0.0.1:8000/)テンプレートが含まれています:
{% include 'polls/header.html' %}
バナーのURLはhttp://127.0.0.1:8000/static/images/banner.jpg
私2ndpageテンプレートも含まれています
{% include 'polls/header.html' %}
しかし、バナーのURLはhttp://127.0.0.1:8000/2ndpage/images/banner.jpg
mに変更されますyのポーリング/ header.htmlテンプレート:
<img src="{{ STATIC_URL }}images/gcs_banner.jpg" />
urls.py
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('polls.views',
url(r'^$', 'index'),
url(r'^2ndpage/$', '2ndindex'))
views.py
def index(request):
...
return render_to_response('polls/index.html', {'latest_people_list': latest_people_list,}, context_instance = RequestContext(request))
def 2ndpage(request, people_id):
...
return render_to_response('index/detail.html', {'people': p}, context_instance = RequestContext(request))
なぜ../static/ ..からURLの変更はしません。 ./2ndpage/..? {%include 'polls/header.html'%}を使用すると、バナーが常に表示されるように、どうすれば修正できますか?
第2ページの表示コードを貼り付けてください。 – jpic
私は別の質問から答えを見つけました。基本的には、context_instance = RequestContext(request)を追加するだけです。しかし、私はこれが何をしているのか、なぜ私はいつもそれを追加する必要があるのか理解していません。誰かが簡単に説明できますか? – thedeepfield