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>
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?
There is a static context-processor (Version 1.8), which isn’t the same as the
mediaone. You need to make sure you havedjango.core.context_processors.staticin your context-processor list, so it can addSTATIC_URLto the context.As commented, for Django 3.0, that is now at django.core.context_processors.static. Django sure has changed a lot since 2011…