Django {{MEDIA_URL}}空白@DEPRECATED [英] Django {{ MEDIA_URL }} blank @DEPRECATED
问题描述
我不能得到{{MEDIA_URL}}在settings.py
<$ p中显示
$ p> ..
MEDIA_URL ='http://10.10.0.106/ame/'
..
TEMPLATE_CONTEXT_PROCESSORS =(
django.contrib .auth.context_processors.auth,
django.core.context_processors.media,
)
..
在我看来我有
from django.shortcuts import render_to_response,get_object_or_404
从ame.Question.models import问题
def最新(请求):
Question_latest_ten = Question.objects.all()。order_by('pub_date')[:10]
p = get_object_or_404(Question_latest_ten)
return render_to_response('Question / latest.html',{'latest':p})
然后我有一个base.html和Question / latest.html
{%extends 'base.html'%}
< img class =hlsrc ={{MEDIA_URL}} / images / avatar.jpg/>< / a>
但MEDIA_URL显示空白,我以为这是它的假设,但也许我错了。
更新
最新版本修复了这些问题。
添加媒体模板上下文处理器也可以完成工作
TEMPLATE_CONTEXT_PROCESSORS =(
django.core.context_processors.request,
django.contrib.auth.context_processors.auth,
django.core.context_processors.media,
django.core.context_processors。静态,
)
I have banged my head over this for the last few hours. I can not get {{ MEDIA_URL }} to show up
in settings.py
..
MEDIA_URL = 'http://10.10.0.106/ame/'
..
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.media",
)
..
in my view i have
from django.shortcuts import render_to_response, get_object_or_404
from ame.Question.models import Question
def latest(request):
Question_latest_ten = Question.objects.all().order_by('pub_date')[:10]
p = get_object_or_404(Question_latest_ten)
return render_to_response('Question/latest.html', {'latest': p})
then i have a base.html and Question/latest.html
{% extends 'base.html' %}
<img class="hl" src="{{ MEDIA_URL }}/images/avatar.jpg" /></a>
but MEDIA_URL shows up blank, i thought this is how its suppose to work but maybe I am wrong.
Update Latest version fixes these problems.
Adding media template context processor also gets the job done
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.media",
"django.core.context_processors.static",
)
这篇关于Django {{MEDIA_URL}}空白@DEPRECATED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!