STATIC_URLをテンプレートで参照できるようにする方法
1.settings.pyに割り当てたいURLを記述する
STATIC_URL = 'http://localhost/static'
2.views.pyでテンプレートを呼び出す時にRequestContextを利用する
from django.template import RequestContext, loader from django.http import HttpResponse
def show(request):
template = loader.get_template(‘show.html’)
contexts = RequestContext({})
return HttpResponse(template.lender(contexts))
3.テンプレートファイル(show.html)でSTATIC_URLを使う
{{STATIC_URL}}と指定すると、settings.pyで定義した値を表示できる