I'm somewhat confused as to how Django operates with static content. Essentially, in the settings.py
file, we define MEDIA_URL
which points to the URL to use when resolving static media such as scripts and styles, as well as MEDIA_ROOT
, a reference to where things live on the filesystem.
However, it doesn't seem clear how I can get access to MEDIA_URL
from a template, and it's kind-of-important if I want to use Django's mechanism for loading static content at all. Essentially, I have my base template looking somewhat like this:
<html>
<head>
{% block styles %}
<link rel="stylesheet" href="{{ MEDIA_URL }}styles/master.css"/>
{% endblock %}
<title>{% block title %}Page Title{% endblock %}</title>
</head>
<body>
{% block scripts %}
<script type="text/javascript" src="{{ MEDIA_URL }}scripts/jquery.js"></script>
{% endblock %}
</body>
</html>
Will the above code actually work? I've heard that you have to use other plugins to get something like this up and running, which seems kind of strange, as presumably the whole point behind defining MEDIA_URL
is to use it in templates.