STATIC_URL不工作 [英] STATIC_URL not working
本文介绍了STATIC_URL不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力使用 STATIC_URL 变量为我的模板拉出媒体。例如我有这个代码
I am struggling to pull media out for my templates using the STATIC_URL variable. For example I have this code
{% extends "admin/change_list.html" %}
{% load i18n %}
{% block extrahead %}
<!--[if IE]>
<script type="text/javascript" src="{% firstof STATIC_URL MEDIA_URL %}django_qbe/js/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="{% firstof STATIC_URL MEDIA_URL %}django_qbe/js/jquery.js"></script>
每次模板加载时,都试图拉下 MEDIA_URL 。如果我将其更改为
Each time the template loads it tries to pull off the MEDIA_URL. If I change it to
{% extends "admin/change_list.html" %}
{% load i18n %}
{% load static %}
{% block extrahead %}
<!--[if IE]>
<script type="text/javascript" src="{% get_static_prefix %}django_qbe/js/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="{% get_static_prefix %}django_qbe/js/jquery.js"></script>
我的问题是为什么我的第一个版本的这个模板不工作?
My question is why doesn't my first version of this template work?
推荐答案
有一个静态上下文处理器,它与 media
不一样。您需要确保您的上下文处理器列表中有 django.core.context_processors.static
,因此可以添加 STATIC_URL
到上下文。
There is a static context-processor, which isn't the same as the media
one. You need to make sure you have django.core.context_processors.static
in your context-processor list, so it can add STATIC_URL
to the context.
这篇关于STATIC_URL不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文