Other tags and filters libraries

static

To link to static files that are saved in STATIC_ROOT Django ships with a static template tag. You can use this regardless if you're using RequestContext or not.

{% load static %} 
<img src="{% static "images/hi.jpg" %}" alt="Hi!" /> 

It is also able to consume standard context variables, for example, assuming a user_stylesheet variable is passed to the template:

{% load static %} 
<link rel="stylesheet" href="{% static user_stylesheet %}" type="text/css" media="screen" /> 

If you'd like to retrieve a static URL without displaying it, you can use a slightly different call:

{% load static %} 
{% static "images/hi.jpg" as myphoto %} 
<img src="{{ myphoto }}"></img> 

The staticfiles contrib app also ships with a static ...

Get Mastering Django: Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.