Django {{ MEDIA_URL }} 空白 @DEPRECATED [英] Django {{ MEDIA_URL }} blank @DEPRECATED

查看:25
本文介绍了Django {{ MEDIA_URL }} 空白 @DEPRECATED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几个小时里,我一直在为此烦恼.我无法让 {{ MEDIA_URL }} 出现

I have banged my head over this for the last few hours. I can not get {{ MEDIA_URL }} to show up

在 settings.py 中

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",
)
..

在我看来我有

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})

然后我有一个 base.html 和 Question/latest.html

then i have a base.html and Question/latest.html

{% extends 'base.html' %}
<img class="hl" src="{{ MEDIA_URL }}/images/avatar.jpg" /></a>

但 MEDIA_URL 显示为空白,我认为这就是它的工作方式,但也许我错了.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆